Jacobi iteration what the wrong of my code please help

조회 수: 3 (최근 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 CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by