Problems solving a trigonometric equation with 2 unknowns

6 views (last 30 days)
Hello,
So, I have 2 trigonometric equations, the unknowns here are q2 and q3.
The 2 equations are:
Py=2*cos(q1) * ( cos(q2+q3) + 3*cos(q2) )
Pz=2*sin(q2+q3) + 6*sin(q2) + 14
First I tried on paper to get some function q3=f(q2), and that's what I ended up with:
q3=atan((Pz/2-7-3*sin(q2))/(Py/2/cos(q1)-3*cos(q2)))
Then I tried to solve only the first equation, substituting q3 with that function of q2 like this:
solve((Pz/2-7)==(sin(q2+q3)+3*sin(q2)), q2);
And the answer was: "Warning: Possibly spurious solutions."
I've also tried this, as I've seen in some post here
eqns = [(2*cos(q1)*(cos(q2+q3)+3*cos(q2))) == Py, (2*sin(q2+q3)+3*sin(q2)) == 0];
S = solve(eqns,[q2 q3])
Unsuccesfully tho
In another attempt I wanted to do in Matlab the same thing I did on paper, that is to get some q3=f(q2) and substitute it afterwards in the equation, but I ended up with complex numbers, and that's not something I wanted because q2 and q3 are angles for my robot, and Py and Pz are coordinates of the robot, so I can't get complex angles.
eqn = sin(b+c)+3*sin(b) == z/2-7;
sol = solve(eqn, b)
In this case b=q2, c=q3 and z=Pz. I tried it for the second equation and I got complex numbers too.
In my last attempt I tried a more direct approach
Result=solve(2*cos(q1)*(cos(q2+q3)+3*cos(q2)) == Py,...
2*sin(q2+q3)+6*sin(q2)+14 == Pz ,q2,q3)
But I ended up with complex numbers again and a very long solution too. By no means the result that you should get from a robot with that has the first rotation about the Z-axis and the last 2 about the Y-axis.

Answers (1)

Raynier Suresh
Raynier Suresh on 1 Dec 2020
Edited: Raynier Suresh on 1 Dec 2020
Using “solve” you can solve the equations and using simplify” command you can do algebraic simplifications of the result.
You can use the following code to solve your equation. In the result you can substitute the values for end effector (Py, Pz) and q1 to calculate q2 and q3. By substituting proper value for Py, Pz and q1 you may not get complex values.
syms q1 q2 q3 Py Pz
eqns = [Py==2*cos(q1) * (cos(q2+q3) + 3*cos(q2)), Pz==2*sin(q2+q3) +6*sin(q2) + 14]
vars = [q2 q3]
result = solve(eqns,vars)
q2 = simplify(result.q2)
q3 = simplify(result.q3)
Refer the below documentation links for more information:
  3 Comments
Raynier Suresh
Raynier Suresh on 3 Dec 2020
Unnecessary white spaces in the eqns is what causing this, please replace the eqns with the below one.
eqns = [Py==2*cos(q1)*(cos(q2+q3)+3*cos(q2)), Pz==2*sin(q2+q3)+6*sin(q2)+14]
The result i got was
q2 =
2*atan(((-(132*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2)*(180*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2))^(1/2) - 168*cos(q1)^2 + 12*Pz*cos(q1)^2)/(228*cos(q1)^2 + Pz^2*cos(q1)^2 + 12*Py*cos(q1) + Py^2 - 28*Pz*cos(q1)^2))
-2*atan((168*cos(q1)^2 + (-(132*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2)*(180*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2))^(1/2) - 12*Pz*cos(q1)^2)/(228*cos(q1)^2 + Pz^2*cos(q1)^2 + 12*Py*cos(q1) + Py^2 - 28*Pz*cos(q1)^2))
q3 =
-2*atan((-(132*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2)*(180*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2))^(1/2)/(180*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2))
2*atan((-(132*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2)*(180*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2))^(1/2)/(180*cos(q1)^2 + Pz^2*cos(q1)^2 + Py^2 - 28*Pz*cos(q1)^2))

Sign in to comment.

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!