left and right sides have a different number of elements
4 ビュー (過去 30 日間)
古いコメントを表示
im trying to solve a gauss-seidel method problem and im getting the "left and right sides have a different number of elements" error in the xn(Iter) lines. how do i fix this?
A = [10 -2 -5 30; -2 15 -5 -5; -5 -5 14 25]
C = [2 ; 1 ; 3]
Error = 100;
Thr = 1;
Iter = 0;
x1 = C(1,1);
x2 = C(2,1);
x3 = C(3,1);
while Iter<5
Iter = Iter+1;
x1(Iter) = (A(1,4) - A(1,2)*x2 - A(1,3)*x3)/A(1,1);
x2(Iter) = (A(2,4) - A(2,1)*x1 - A(2,3)*x3)/A(2,2);
x3(Iter) = (A(3,4) - A(3,1)*x1 - A(3,2)*x2)/A(3,3);
x1 = x1(Iter);
x2 = x2(Iter);
x3 = x3(Iter);
end
1 件のコメント
回答 (1 件)
Matt J
2023 年 3 月 22 日
編集済み: Matt J
2023 年 3 月 22 日
A = [10 -2 -5 30; -2 15 -5 -5; -5 -5 14 25];
C = [2 ; 1 ; 3];
Error = 100;
Thr = 1;
Iter = 0;
x1 = C(1,1);
x2 = C(2,1);
x3 = C(3,1);
while Iter<5
Iter = Iter+1;
X1(Iter) = (A(1,4) - A(1,2)*x2 - A(1,3)*x3)/A(1,1);
X2(Iter) = (A(2,4) - A(2,1)*x1 - A(2,3)*x3)/A(2,2);
X3(Iter) = (A(3,4) - A(3,1)*x1 - A(3,2)*x2)/A(3,3);
x1 = X1(Iter);
x2 = X2(Iter);
x3 = X3(Iter);
end
X1,X2,X3
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!