Solve a system of nonlinear equations with trigonometric functions

1k views Asked by At

I've got the following equations:

q1dd,b1,q2,q3,v1,q2dd,a1,a2,b2 = symbols('\ddot{q}_1 b1 q2 q3 v1 \ddot{q}_2 a1 a2 b2')
eq1 = -q1dd+b1*cos(q2)*sin(q3)*v1
eq2 = -q2dd+a1*sin(q2)+a2*cos(q2) + b2*cos(q3)*v1
display(eq1)
display(eq2)

According to sympy rules these are -lhs+rhs=0. Thus, both equations are equal to zero. I'd like to solve the set in sympy

sol1 = nonlinsolve([eq1,eq2],[v1,q3])
sol2 = solve([eq1,eq2],[v1,q3])

however, the result is super complicated. Also trigsimp and simplify do not change the solution. By hand I can just divide eq1/eq2 = 0 and solve for tan(q3) and solve eq1 for v1. This is a very short solution. My question is: am I doing something wrong (other solver, form of parametrization,handling,...), or is sympy just not ready yet to solve these things as elegantly?

1

There are 1 answers

1
AudioBubble On BEST ANSWER

Your approach is not wrong. SymPy, or other programs, are not about to replace people with some knowledge of mathematics. In this case the nonlinear solvers miss the opportunity to simplify sin(q3)/cos(q3) to tan(q3), thus reducing the number of appearances of q3 to one. If they are pushed to follow a particular strategy - e.g., "solve for v1 from the first, sub into the second, simplify and solve for q3" - the solution comes out without much fuss.

v1sol = solve(eq1, v1)[0]
q3sol = solve(simplify(eq2.subs(v1, v1sol)), q3)[0]
print([v1sol, q3sol])

This outputs

[\ddot{q}_1/(b1*sin(q3)*cos(q2)), -atan(\ddot{q}_1*b2/(b1*(-\ddot{q}_2 + a1*sin(q2) + a2*cos(q2))*cos(q2)))]