Jacobi iteration what the wrong of my code please help

2 次查看(过去 30 天)
% 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];

请先登录,再进行评论。

更多回答(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