I'm having trouble using Sympy to solve an equation. When I run the code, for example:
print(correction(10))
I expect it to print a number which is f. Instead it gives me ERROR: execution aborted.
def correction(r):
from sympy import cosh, log, exp, symbols, solve
f = symbols('f')
def equation():
return cosh(((r - 1.0)/(r + 1.0))*(log(2.0)/f)) - 0.5*exp(log(2.0)/f)
correction = solve(equation(),f)
return correction
What is the problem?
Your equation is highly non-linear and my guess is that a closed-form solution cannot be found. That's why
sympy.solve
fails. The only option you have is to solve the equation numerically. Sympy offers thensolve
function for this purpose, which, as typical in numerical solvers, requires an estimate of the solution.