프로그래머의 삶 Programmer's Life/Python, Numpy, Pandas

Solving equations algebraically by Sympy library

Oliver's World 2022. 6. 9. 17:47
728x90

Sympy library provides "solve" function to calculate the polynomial equation.

Sympy 라이브러리는 다항식을 계산하는 "solve" 기능을 제공합니다.

 

As the programming language, it should provide a "Symbol" to know by the system to calculate. 

프로그래밍 언어로서 방정식을 계산하기 위하여 시스템이 알 수 있는 "기호"를 제공해야 합니다.

 

a = Symbol('a')
b = Symbol('b')

 

After then, we can state equations like the below.

그리고나서, 우리는 아래와 같은 방정식을 나타낼 수 있습니다.

 

ex1 = a + b - 1
ex2 = 5 * a + b - 3

 

 

Lastly, using the "solve" function to get the result.

마지막으로 "Solve" 기능을 사용하여 결과물을 얻습니다.

# Algebraically solves equations and systems of equations
print(solve((ex1, ex2)))

 

 

Here is the result.

결과는 여기에~



728x90