Jacobi iteration what the wrong of my code please help
2 views (last 30 days)
Show older comments
ayah zaghlol
on 12 May 2021
Commented: Walter Roberson
on 13 May 2021
% 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
0 Comments
Accepted Answer
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
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!