오류를 해결해서 답을 도출하고싶어요. (결합하려는 배열의 차원이 일치하지 않습니다.)

30 次查看(过去 30 天)
gyul
gyul 2024-5-1
移动Angelo Yeo 2024-5-3
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
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
-----------------------------------------------
다음 사용 중 오류가 발생함: horzcat
결합하려는 배열의 차원이 일치하지 않습니다.
오류 발생: test (31번 라인)
X(itr,:)=[itr,Re, xn'];

回答(1 个)

lazymatlab
lazymatlab 2024-5-2
移动:Angelo Yeo 2024-5-3
말 그대로 크기가 맞지 않습니다.
itr은 1x1이고 Re는 3x1이고 xn'는 1x3이라서 가로방향(horizontal)으로 합칠 수 없습니다.

类别

Help CenterFile Exchange 中查找有关 빅 데이터 처리 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!