Jacobi iteration what the wrong of my code please help

2 ビュー (過去 30 日間)
ayah zaghlol
ayah zaghlol 2021 年 5 月 12 日
コメント済み: Walter Roberson 2021 年 5 月 13 日
% jacobi Method
clc
clear
format short
A=[2.08 -1 0 0;-1 2.08 -1 0;0 -1 2.08 -1;0 0 -1 2.08];
b=[200.0 0.8 0.8 40.8];
l=tril(-A,-1);
u=triu(-A,1);
d=diag(diag(A));
tj=inv(d)*(l+u);
cj=inv(d)*b;
xj=[1;1;1];
N=5;
for i=1:N
xj=tj*xj+cj;
[i xj']
end

採用された回答

Walter Roberson
Walter Roberson 2021 年 5 月 12 日
size(d) is 4 x 4, so size(inv(d)) is 4 x 4.
size(b) is 1 x 4.
You cannot use matrix multiplication * operator between a 4 x 4 and a 1 x 4. The second dimension of the first operand (4 here) must match the first dimension of the second operand (1 here)
  3 件のコメント
ayah zaghlol
ayah zaghlol 2021 年 5 月 12 日
編集済み: Walter Roberson 2021 年 5 月 13 日
Ok Thank you I want to solve this matrix for n of iterations how?
A=[2.08 -1 0 0;-1 2.08 -1 0;0 -1 2.08 -1;0 0 -1 2.08]; b=[200.0 0.8 0.8 40.8];
Walter Roberson
Walter Roberson 2021 年 5 月 13 日
I do not understand what you are asking for?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by