필터 지우기
필터 지우기

help me fix my code

조회 수: 3 (최근 30일)
bachir
bachir 2015년 10월 19일
편집: Walter Roberson 2015년 10월 19일
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
Varun Pai
Varun Pai 2015년 10월 19일
dt23 is 2x2 matrix, whereas t is 2x1 matrix. Matrix dimensions do not agree. What is this code ? Use debugger to fix your errors.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by