Hi, how can I solve algebraic equations in python?
For example: 100*X=200, which would return 2.
Is there some sort of library for this?
Thanks!
For example: 100*X=200, which would return 2.
Is there some sort of library for this?
Thanks!
Basic algebra in Python
|
Hi, how can I solve algebraic equations in python?
For example: 100*X=200, which would return 2. Is there some sort of library for this? Thanks!
Sep-14-2017, 03:41 PM
Take a look at sympy solvers: http://docs.sympy.org/latest/modules/sol...lvers.html
You can download the source to see how they do it: https://github.com/sympy/sympy/releases
Thanks, I'll give it a try!
When running this code: from sympy.solvers import solve from sympy import Symbol x = Symbol('x') print solve(x*2 - 5, x).evalf()it gives this error: How can I get it to return a decimal result?
Sep-14-2017, 06:53 PM
Doesn't
solve() already return the result? Why are you eval()ing it?
It seems to result in the same error whether I eval it or not
But I will remove that from my code
Sep-14-2017, 08:40 PM
this code
Quote:from sympy.solvers import solve from sympy import Symbol x = Symbol('x') print solve(x*2 - 5, x) does not produce that error for me but the output Can you show the entire traceback that you are getting?
Recommended Tutorials:
Sep-14-2017, 08:48 PM
from sympy.solvers import solve from sympy import Symbol x = Symbol('x') print solve(x*2 - 5, x) To clarify, I am using python 2.7What I would like it to do would be to output in decimal As for the different results (and 9/40 makes no sense), maybe this could be due to python2.7?
Sep-14-2017, 09:21 PM
Works for me.
It's complaining about line 17 in main.py Is this your module (main.py)? if it is, why no line 17? if not, why no line from your module in traceback?
What I have posted is my complete script.
What version of python are you using? Also, I want to thank all of you guys for helping me, earlier I asked a similar question on StackOverflow and it got put on hold because the quality 'wasn't good enough'.
Sep-14-2017, 11:51 PM
Shouldn't matter, but my code is always done with the latest version which is currently 3.6.2
|
|