How to solve the equation to get the result in atan2 form?

4 views (last 30 days)
Hello MATLAB Community,
I am trying to solve an equation in MATLAB, but I don't know which function or how to solve it.
syms phi theta psi
ROT = [cos(theta)*cos(phi)+sin(psi)*sin(theta)*sin(phi), -cos(theta)*sin(phi)+sin(psi)*sin(theta)*cos(phi), cos(psi)*sin(theta); ...
cos(psi)*sin(phi), cos(psi)*cos(phi), -sin(psi); ...
-sin(theta)*cos(phi)+sin(psi)*cos(theta)*sin(phi), sin(theta)*sin(phi)+sin(psi)*cos(theta)*cos(phi), cos(psi)*cos(theta)];
eqn = ROT(1,2) == ROT(2,1)
I tried to use functions like solve, simplify, etc. but I am not getting it in the desired form as shown below:
psi = atan2(sin(phi)*sin(theta),cos(phi)+cos(theta))
Can anyone please help me with any suggestions.
Thank you in advance!!
I really appreciate your help.
Kind regards,
Shiv
  5 Comments
Mohammed Hamaidi
Mohammed Hamaidi on 23 Mar 2022
Be careful. The equation has solution under some strict assumptions.
Example:
sin(x)+cos(x)==4
, has no solution,
Matlab gives:
>> solve(cos(x)+sin(x)==4,x)
ans =
-log(- 28i^(1/2)/2 + (2 + 2i))*1i
-log(28i^(1/2)/2 + (2 + 2i))*1i
So, you have to give the assumptions/conditions

Sign in to comment.

Answers (1)

Torsten
Torsten on 21 Mar 2022
Edited: Torsten on 21 Mar 2022
syms phi theta psi
ROT = [cos(theta)*cos(phi)+sin(psi)*sin(theta)*sin(phi), -cos(theta)*sin(phi)+sin(psi)*sin(theta)*cos(phi), cos(psi)*sin(theta); ...
cos(psi)*sin(phi), cos(psi)*cos(phi), -sin(psi); ...
-sin(theta)*cos(phi)+sin(psi)*cos(theta)*sin(phi), sin(theta)*sin(phi)+sin(psi)*cos(theta)*cos(phi), cos(psi)*cos(theta)];
eqn = ROT(1,2) == ROT(2,1);
sol = solve(eqn,psi)
  11 Comments
Torsten
Torsten on 23 Mar 2022
Edited: Torsten on 23 Mar 2022
You didn't get David's point.
Your formula to calculate psi as
psi = atan2(sin(phi)*sin(theta),cos(phi)+cos(theta))
seems to be wrong.
But now you know the solution to write psi in terms of phi and theta in symbolic form (the expression from octave). Why don't you simply copy it and use it in your code or whereever you need it ?
Shiv Karpoor
Shiv Karpoor on 23 Mar 2022
Oh, Okay.
Might be wrong I can't tell, because I got it from journal paper.
I will do as suggested,
Thanks Torsten, I appreciate your help!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!