Jacobi iteration what the wrong of my code please help

2 views (last 30 days)
% 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

Accepted Answer

Walter Roberson
Walter Roberson on 12 May 2021
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 Comments
ayah zaghlol
ayah zaghlol on 12 May 2021
Edited: Walter Roberson on 13 May 2021
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];

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!