SymPy achieve solution of the equation

https://www.cnblogs.com/zgyc/p/6277562.html

 SymPy is completely written in Python and does not require external libraries

principle:

Simply use the built-in arithmetic and language variables to address is, find the result by the value. Such as:

print (x + y) # being given

In the above formula x and y before this statement you definitely have to execute the assignment, otherwise it will go wrong.

The different symbolic computation, before you can set it to sign.

Symbol x = ( 'x') 
y = Symbol ( 'y') 
print (x + y)

The code is possible. Because Sympy library x and y converted into symbols (conceptually). After the introduction, you should know a little bit, through the following presentation, you will be more aware

Step 1: Install SymPy library

Environmental linux installation command: sudo pip install sympy

windows environment installation command: pip install sympy

Step two: linear equations solution functions to achieve

Function mainly by solution of the equation in the solve function sympy

 Example Title: 3x + 5y = 19

                  4x-3y = 6

Equation notation:

Copy the code
from sympy import *

x = symbol('x')
y = symblo('y')

------------------------------#或
from sympy import *

x,y = symbols('x y')
Copy the code

The code represents the handwriting is still a difference, commonly listed below:

  • Plus +
  • Minus -
  • Division sign /
  • Multiplication sign *
  • index**
  • Log log ()
  • e power exponent exp ()

For a long expression, if in doubt, add parentheses

Expression can be expressed as in the example: 3 * x + 5 * Y - 19 = 0

                                  4 * x - 3 * - 6 = 0

Since the expression is converted into the required right is equal to 0, where the constant 19 to the left and Equation 6

Function Solution solve equations using

Prior to solve the example, we first solve a one dollar equation.

x * 9 - 6 = 0

While it is easy to work out the mouth, we use the function solve

print(solve(x * 9 - 6,x))

Solving example below:

Complete code

Copy the code
from Sympy import * 

x = symbol ( 'x') 

y = symbol ( 'y') 

print (solve ([3 * and + 5 * and - 19 4 * x - 3 * - 6], [x, y ]))
Copy the code

The result is {x: 3, y: 2}

Summary: The above brief introduction SymPy library, and the library with SymPy solve math problems in junior high school - linear equations, the following describes how to solve math problems more difficult - Calculus Related exercises

Guess you like

Origin www.cnblogs.com/zkwarrior/p/11089933.html