dt23 is 2x2 matrix, whereas t is 2x1 matrix. Matrix dimensions do not agree. What is this code ? Use debugger to fix your errors.
help me fix my code
1 次查看(过去 30 天)
显示 更早的评论
I ran this code a few times and for some reason it gets stuck at line 14 and I get this message: Matrix dimensions must agree. I would appreciate the help on how to fix it.
r1 = 7; r2 =3; r3 = 8; r4 = 6;
th2 = 0:5:2*pi;
th3 = 0;
th4 = 100;
d2r = pi/180; t2 = d2r*th2;t3 = d2r*th3; t4 = d2r*th4; t = [t3;t4];
f1 =1; f2 = 1; n=1;
while(abs(f1)>0.001 || abs(f2)>0.001)
f1 = r1 + r4.*cos(t4)-r3.*cos(t3)-r2.*cos(t2);
f2 = r4.*sin(t4)-r3.*sin(t3)-r2.*sin(t2);
G = [r3.*sin(t3) -r4.*sin(t4);-r3.*cos(t3) r4.*cos(t4)];
dt23 = G\[f1;f2];
%t3 = t3 - dt23(1)
%t4 = t4 - dt23(2)
t= t-dt23; <===============================================================================Line 14
t3 =t(1); t4 = t(2);
n = n+1;
if(th2<= 2*pi)
th2=th2+5;
disp(['theta3 = ' num2str(theta3) ' theta4 = ' num2str(theta4) ' number of iter= ' num2str(n)]);
end
if n>25
disp(['no convergence n = ' num2str(n)])
break
end
end
theta3 = (180/pi)*t3;
theta4 = (180/pi)*t4;
disp(['theta3 = ' num2str(theta3) ' theta4 = ' num2str(theta4) ' number of iter= ' num2str(n)]);
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!