Python Forum
Solve simple equation in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solve simple equation in Python
#1
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
Reply
#2
For solving symbolic math equations take a look at SymPy
Reply
#3
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)
Output:
2.4
Reply
#4
(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.
Reply
#5
I have never used SymPy myself, but from this tutorial I think it looks fairly straight forward:

https://pythonforundergradengineers.com/...tions.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.
kmll likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Heart how to solve complex equations in python HoangF 3 268 Dec-26-2021, 07:04 PM
Last Post: HoangF
  NotImplementedError: pseudo-class is not implemented - how to Update Python to solve apollo 1 1,171 May-16-2021, 08:03 AM
Last Post: buran
  Python gives " -0.0 " as solution for an equation akar 2 813 Aug-27-2020, 12:15 PM
Last Post: akar
  Asking for help in solving a single variable nonlinear equation using Python ! NDP 0 1,186 Feb-15-2019, 12:03 PM
Last Post: NDP
  How do I code this equation in python (factor ceiling(2^127-1)) Pleiades 5 2,544 Apr-23-2018, 03:01 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020