[Solved] Solving an equation with python


You can do things like this with the sympy library.

http://docs.sympy.org/dev/index.html

>>> from sympy import *
>>> from sympy.solvers import solve

>>> ca, ra = symbols("ca ra")

>>> eq = -ra + (1.5 * (ca - (ra/2))/(1 + 0.8 * (ca - (ra/2))))

>>> print(eq)
-ra + (1.5*ca - 0.75*ra)/(0.8*ca - 0.4*ra + 1)

>>> solutions = solve(eq, ra)  #solve equation for ra
>>> print(solutions)
[ca - 0.0625*sqrt(256.0*ca**2 + 160.0*ca + 1225.0) + 2.1875,
 ca + 0.0625*sqrt(256.0*ca**2 + 160.0*ca + 1225.0) + 2.1875]

>>> values = [s.replace(ca, 5) for s in solutions]  #get solutions for ca=5

[1.45076257791068, 12.9242374220893]

Obviously you’ll need to get a number from your user for ca instead of just solving for ca=5.

solved Solving an equation with python