Solve simple equation in Python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Solve simple equation in Python (/thread-30690.html) |
Solve simple equation in Python - kmll - Nov-01-2020 Hi, I am fairly new to working with mathematics in Python and I am wondering how I can use Python so solve an eqations like this: 0.4x - 0.38 = 0.58 Thanks RE: Solve simple equation in Python - deanhystad - Nov-01-2020 For solving symbolic math equations take a look at SymPy RE: Solve simple equation in Python - jefsummers - Nov-01-2020 Or use basic algebra to solve for x then print the result 0.4x - 0.38 = 0.58 0.4x = 0.58 + 0.38 = 0.96 x = 0.96/0.4 print(0.96/0.4)
RE: Solve simple equation in Python - kmll - Nov-01-2020 (Nov-01-2020, 03:43 PM)deanhystad Wrote: For solving symbolic math equations take a look at SymPy Thanks for the advise. But I did and I did not quite understand how I can use if for an equation similar to the one I listed above so I was hoping for a concrete solution/example. RE: Solve simple equation in Python - deanhystad - Nov-01-2020 I have never used SymPy myself, but from this tutorial I think it looks fairly straight forward: https://pythonforundergradengineers.com/sympy-expressions-and-equations.html My first shot would be: from sympy import symbols, Eq, solve x = symbols('x') eq = Eq('0.4x - 0.38 - 0.58') solution = solve((eq), (x))There may be a way to solve an equation without first putting it in the form equation = 0. I don't know. |