フィルターのクリア

"Check for incorrect argument data type or missing argument in call to function 'X'. Error in sum=sum+A(j,h)*X(h)

1 回表示 (過去 30 日間)
output= ('Gaussian Elimination Method')
A=input ('Enter your coefficient Matrix')
b=input ('Enter your space vector')
N=length(b);
x=zeros(N,1);
for j=1:1:N-1 %Forward Elimination
for i = j+1:1:N
m=A(i,j)/A (j,j);
A(i,:)=A(i,:)- m*A(j,:)
b(i) = b(i) - m*b(j)
end
end
disp([A,b]);
for j=N:-1:1%Backward Elimination
sum=0;
for h=1+1:1:N
sum=sum+A(j,h)*X(h);
end
X(j)=(b(j)-sum)/A(j,j);
end
disp(X);

採用された回答

Chunru
Chunru 2021 年 12 月 5 日
output= ('Gaussian Elimination Method')
output = 'Gaussian Elimination Method'
% A=input ('Enter your coefficient Matrix')
% b=input ('Enter your space vector')
A = randn(3,3);
b = randn(3,1)
b = 3×1
-1.0379 0.3246 0.2563
N=length(b);
X=zeros(N,1); % upper case X (use case carefully)
for j=1:1:N-1 %Forward Elimination
for i = j+1:1:N
m=A(i,j)/A (j,j);
A(i,:)=A(i,:)- m*A(j,:)
b(i) = b(i) - m*b(j)
end
end
A = 3×3
-1.6440 0.8403 -0.7771 0 -1.4609 -0.1171 -0.6397 0.9495 -0.2362
b = 3×1
-1.0379 0.4488 0.2563
A = 3×3
-1.6440 0.8403 -0.7771 0 -1.4609 -0.1171 0 0.6225 0.0662
b = 3×1
-1.0379 0.4488 0.6602
A = 3×3
-1.6440 0.8403 -0.7771 0 -1.4609 -0.1171 0 0 0.0163
b = 3×1
-1.0379 0.4488 0.8514
disp([A,b]);
-1.6440 0.8403 -0.7771 -1.0379 0 -1.4609 -0.1171 0.4488 0 0 0.0163 0.8514
for j=N:-1:1%Backward Elimination
s=0; % try not use sum as variable as it is a built in function
for h=1+1:1:N
s=s+A(j,h)*X(h);
end
X(j)=(b(j)-s)/A(j,j);
end
disp(X);
-26.3721 -4.4960 52.2675

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by