Reputation: 1801
I'm trying to solve the following system of non-linear equations using SymPy:
where are the unknowns (the rest are known parameter symbols).
My code is:
import sympy as sy
sy.init_printing()
m, v0, k, g, R, u, v = sy.symbols('m v0 k g R u v')
sy.nonlinsolve([0.5*m*v0**2 - m*g*2*R - 0.5*m*v**2 - 0.5*k*m*u**2,
m*v0 - m*v - k*m*u, m*g - m*((u+v)**2)/R], [v0, v, u] )
But I'm getting infinite process time and have to interrupt the kernel. Also, I know that the solution for v0 is:
Is there a better way to solve it? Maybe another solver? Or maybe there is a way to get Python check if the solution I have works?
Thank you !!!
Upvotes: 1
Views: 4493
Reputation: 1801
I've got it using some added flags into the solve function:
When I did:
import sympy as sy
sy.init_printing()
m, v0, k, g, R, u, v = sy.symbols('m v0 k g R u v') #Define Symbols
sy.solve((0.5*m*v0**2 - m*g*2*R - 0.5*m*v**2 - 0.5*k*m*u**2,
m*v0 + m*v - k*m*u, m*g - m*((u+v)**2)/R), [v0,u,v] ,
force=True, manual=True, set=True)
It worked!! the 'force'
and 'manual'
flags did the trick!
Upvotes: 4