Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I solve equations in Python? [closed]

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.

like image 554
user1221937 Avatar asked May 08 '12 13:05

user1221937


People also ask

Can you solve equations in 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.

What does solve () do in Python?

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.


1 Answers

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…

like image 162
eumiro Avatar answered Sep 28 '22 10:09

eumiro