오류를 해결해서 답을 도출하고싶어요. (결합하려는 배열의 차원이 일치하지 않습니다.)
26 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
A=[2 3 4; 3 5 6; 1 3 2];
b=[7; 5; 9];
AM=[A, b];
n=size(AM);
nr=n(1);
nc=n(2);
b=AM(:,nc);
itr=1; max_itr=30; tolerance=0.03;
xn=zeros(3,1); X=zeros(max_itr,nr+2);
xo=[1;1;1];
while true
for i=1:1:nr
s1=0; s2=0;
if i~=1
s1=AM(i,1:i-1)*xo(1:i-1);
elseif i~=nr
s2=AM(i,i+1:nr)*xo(i+1:nr);
end
s=s1+s2;
xn(i)=(b(i)-s)/AM(i,i);
end
Re=abs(max(xn-xo)./xo);
if Re <= tolerance
for i=1:1:nr
fprintf('x(%d)=%f\n',i,xn(i));
end
break;
elseif itr > max_itr
break;
else
X(itr,:)=[itr,Re, xn'];
itr=itr+1;
xo=xn;
end
end
-----------------------------------------------
다음 사용 중 오류가 발생함: horzcat
결합하려는 배열의 차원이 일치하지 않습니다.
오류 발생: test (31번 라인)
X(itr,:)=[itr,Re, xn'];
0 Kommentare
Antworten (1)
lazymatlab
am 2 Mai 2024
Verschoben: Angelo Yeo
am 3 Mai 2024
말 그대로 크기가 맞지 않습니다.
itr은 1x1이고 Re는 3x1이고 xn'는 1x3이라서 가로방향(horizontal)으로 합칠 수 없습니다.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Acquisition Toolbox Supported Hardware finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!