Let's say I have an equation:
2x + 6 = 12
With algebra we can see that x = 3
. How can I make a program in Python that can solve for x
? I'm new to programming, and I looked at eval()
and exec()
but I can't figure out how to make them do what I want. I do not want to use external libraries (e.g. SAGE), I want to do this in just plain Python.
Sympy is a package for symbolic solutions in Python that can be used to solve systems of equations. The same approach applies to linear or nonlinear equations.
solve() method. With the help of sympy. solve(expression) method, we can solve the mathematical equations easily and it will return the roots of the equation that is provided as parameter using sympy.
How about SymPy? Their solver looks like what you need. Have a look at their source code if you want to build the library yourself…
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With