How to solve the equation to get the result in atan2 form?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Mohammed Hamaidi
2022-3-23
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
回答(1 个)
Torsten
2022-3-21
编辑:Torsten
2022-3-21
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 个评论
Torsten
2022-3-23
编辑:Torsten
2022-3-23
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 ?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!