How to solve overdetermined vector equation?
Show older comments
Hi,
I have an equation like this:
sin(a1)*sin(a2)=v1, -cos(a1)*sin(a2)=v2, cos(a2)=v3
v1, v2 and v3 are components of a vector I know. How can I calculate the equation to get the results of a1 and a2?
Thanks!
Answers (2)
Torsten
on 6 Jul 2015
1 vote
Use lsqnonlin to minimize the function
F(a1,a2) = (sin(a1)*sin(a2)-v1)^2 + (cos(a1)*sin(a2)+v2)^2 + (cos(a2)-v3)^2
Best wishes
Torsten.
Bjorn Gustavsson
on 6 Jul 2015
Use pen and paper, draw the standard little sketch for spherical-and-Cartesian coordinates...
Then you get:
a2 = acos(v3);
% sin(a1)/cos(a1) = -v1/v2, so
a1 = atan2(v1,-v2); % check the order of the arguments to atan2
% perhaps this is a numerically better estimate of a2:
a2 = atan((v1^2+v2^2)^(1/2)/v3);
HTH
2 Comments
Torsten
on 6 Jul 2015
I get
a2 = -atan((v1^2+v2^2)^(1/2)/v3);
Best wishes
Torsten.
Bjorn Gustavsson
on 6 Jul 2015
Realy? Oh, well - no reason for us to get all agitated about sign conventions for rotational angles...
(I've seen 4 different definitions of azimuth used in astronomy! Clock-wise from North, counter-clock-wise from East, clock-wise from East, clock-wise from East)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!