我基本上有一个28参数的非线性方程。当f(x) = 0
时,我可以测量14个参数,并且我有数据生成133个方程,其中包含14个测量参数。我现在需要找到导致最小残差的14个未知参数(无约束)的值。
我相信MATLAB优化工具箱(fsolve
)应该完成这项工作。我的目标函数是3个转换矩阵的乘积,因此很长,没有明确写出。
function fRMS= MyObjectiveFunction(xi)
syms sx sy aa bb cc ro tau omega x y z alpha beta gamma
xi = [ sx, sy, aa, bb, cc, ro, tau, omega, x,y,z, alpha, beta, gamma];
load CalibData.mat n1 n2 n3 n4 n5 n6 n7 n8 n9 t1 t2 t3 u v
rTp=[cos(omega)*cos(tau) cos(omega)*sin(tau)*sin(ro)-sin(omega)*cos(ro) cos(omega)*sin(tau)*cos(ro)+sin(omega)*sin(ro) aa;...
sin(omega)*cos(tau) sin(omega)*sin(tau)*sin(ro)+cos(omega)*cos(ro) sin(omega)*sin(tau)*cos(ro)-cos(omega)*sin(ro) bb;...
-sin(tau) cos(tau)*sin(ro) cos(tau)*cos(ro) cc;...
0 0 0 1];
cTt=[cos(alpha)*cos(beta) cos(alpha)*sin(beta)*sin(gamma)-sin(alpha)*cos(gamma) cos(alpha)*sin (beta)*cos(gamma)+sin(alpha)*sin(gamma) x;...
sin(alpha)*cos(beta) sin(alpha)*sin(beta)*sin(gamma)+cos(alpha)*cos(gamma) sin(alpha)*sin(beta)*cos(gamma)-cos(alpha)*sin(gamma) y;...
-sin(beta) cos(beta)*sin(gamma) cos(beta)*cos(gamma) z; 0 0 0 1]; % (labspace to bucket space)
for frame=1:133 % 133 frames
tTr(:,:,frame)=[n1(frame) n2(frame) n3(frame) t1(frame); n4(frame) n5(frame) n6(frame) t2 (frame); n7(frame) n8(frame) n9(frame) t3(frame); 0 0 0 1];
Px(:,frame)=[sx*u(frame); sy*v(frame); 0; 1];
Cx(:,frame)= cTt*tTr(:,:,frame)*rTp*Px(:,frame);
f(frame)= Cx(3,frame); % Z=0
end
fRMS=rms(f); % Objective function
使用优化工具箱时,出现以下错误。这可能是我将值传递给符号变量的结果。我非常感谢您帮助解决错误或提供替代方法来解决这个问题。
Error using mupadmex
Error in MuPAD command: DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use the VPA function instead.
非常感谢!!