ValientProcess
ValientProcess

Reputation: 1801

Solving non-linear set of symbolic equations with SymPy (Python)

I'm trying to solve the following system of non-linear equations using SymPy:

enter image description here

where enter image description here 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:

enter image description here

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

Answers (1)

ValientProcess
ValientProcess

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

Related Questions