I can't find where my mistake is?

1 次查看(过去 30 天)
DS
DS 2019-2-21
回答: Takumi 2019-2-21
A=[1 2 -1; 2 2 -1; 2 5 2];
b=[3; 4; 2];
x=[1; 1; 1];
tol=1e-7;
d=diag(A);
X=ones(3,1);
r=ones(3,1);
while norm(r)/norm(X)>=tol
X=(b-A*x)./d+x;
r=X-x;
x=X;
end
X
%X should be 1 4/9 -10/9
  1 个评论
Bob Thompson
Bob Thompson 2019-2-21
It seems like your system is unstable, as X just perpetually increases in value. Without knowing the equation you're trying to code I don't know that I can help much more than that, but I would look at the X value equation some more.

请先登录,再进行评论。

回答(1 个)

Takumi
Takumi 2019-2-21
In the Jacobi method, matrix 'A' must be diagonally dominant.

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by