Giter Site home page Giter Site logo

numerical-solution-to-equations-systems's Introduction

Numerical Solution to Equations Systems

A Python based code to numerically solve generic equations systems.

Problem description

This code solve numerically a system of generic (linear and non-linear) equations using Newton Method

Dependences

  • Python 3.8.3
  • Python Numpy library
  • Python SymPy library

How to use

There two main files in this project non_linear_equations.py and non_linear_solver.py.

From they, you want import Equation and EquationSolver, respectively.

The Equation class

Equation class is a SymPy based class structured to store a set of equations and evaluate this system at a given point.

  1. Constructor

       Recive a list of SymPy expressions and a tuple containing the set of symbols (in String) that compose the system

  1. Equation.str_to_expression(string_expression_list)

       Recive a list of Strings and parse to SymPy expression

Ex.

from non_linear_equations import Equation
string_expressions = ["x**2 + y**2 + z**2 - 8",
                      "x**2 + y**2 - z**2",
                       "y**2 - x + z - 3"]
expr = Equation.str_to_expression( string_expressions )
  1. obj.at(self, values)

       Evaluate the system in a given point

Ex.

from non_linear_equations import Equation


expr = Equation.str_to_expression( ["x**2 + y**2 + z**2 - 8",
                                    "x**2 + y**2 - z**2",
                                    "y**2 - x + z - 3"])
expr = Equation( expr, ('x', 'y', 'z') )
eval = expr.at( (2,3,4) ) # Respect the given in the constructor
print(eval)
>>Console output
[-8.  0. -3.]

The EquationSolver class

  1. Constructor

       Recive a Equation class

  1. obj.solve(self, initial_values, stop_criterion, max_iterations = 30, stop_criterion_value = 0.01, generate_output_info = False [WIP])

       Solve a determinated Equation System and return the solution vector in Numpy.ndarray type.

This method is the core of the program, it will tries to solve the given sytem with Newton Method.

Parameter Meaning Default value
initial_values The initial values of method aproximation, should be close enough to the real solution to garantee convergence -
stop_criterion Should be EquationSolver.max_relative_error or EquationSolver.max_absolute_error -
max_iterations The max number of steps to tries hit the stop_criterion before the method returns 30
stop_criterion_value The values that the stop_criterion needs to get to reach the convergence and return a solution 0.01

Ex.

from non_linear_equations import Equation
from non_linear_solver import EquationSolver


expr = Equation.str_to_expression( ["x**2 + y**2 + z**2 - 8",
                                    "x**2 + y**2 - z**2",
                                    "y**2 - x + z - 3"])
expr = Equation( expr, ('x', 'y', 'z') )

equation_solver = EquationSolver(expr)

solution = equation_solver.solve( (1.5, 2.1, 3.4),
                                  EquationSolver.max_relative_error,
                                  stop_criterion_value=0.1)

print(solution)
print(type( solution ))
>>Console output
[1.3028102  1.5174782  2.00008165]
<class 'numpy.ndarray'>

numerical-solution-to-equations-systems's People

Contributors

jaumpedro214 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.