MATLAB: Solver for overdetermined system of non-linear equations

equationmatrixsolve

Hello!
I have numeric rotation matrix F, for example:
F = [0.7392 -0.6653 -0.1051;
0.6727 0.7370 0.0659;
0.0337 -0.1194 0.9923]
Also I have symbolic rotation matrix R:
syms th1 th2 th3
Z = [cos(th3) -sin(th3) 0; sin(th3) cos(th3) 0; 0 0 1];
Y = [cos(th2) 0 sin(th2); 0 1 0; -sin(th2) 0 cos(th2)];
X = [1 0 0; 0 cos(th1) -sin(th1); 0 sin(th1) cos(th1)];
R = Z*Y*X;
Basically, I want to solve R == F for [th1, th2, th3]. What built-in Matlab function should I use? Thanks in advance!

Best Answer

I use fsolve here:
syms th1 th2 th3
Z = [cos(th3) -sin(th3) 0; sin(th3) cos(th3) 0; 0 0 1];
Y = [cos(th2) 0 sin(th2); 0 1 0; -sin(th2) 0 cos(th2)];
X = [1 0 0; 0 cos(th1) -sin(th1); 0 sin(th1) cos(th1)];
R = Z*Y*X;
Rfcn = matlabFunction(R, 'Vars',{[th1, th2, th3]});
F = [0.7392 -0.6653 -0.1051;
0.6727 0.7370 0.0659;
0.0337 -0.1194 0.9923];
th_vct = fsolve(@(in1) Rfcn(in1) - F, 2*pi*rand(1,3));
fprintf(1, 'th1 = %7.4f\nth2 = %7.4f\nth3 = %7.4f\n', th_vct)
th1 = -0.1198
th2 = -0.0337
th3 = 0.7383