help me fix my code
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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)]);
1 commentaire
Varun Pai
le 19 Oct 2015
dt23 is 2x2 matrix, whereas t is 2x1 matrix. Matrix dimensions do not agree. What is this code ? Use debugger to fix your errors.
Réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!