I can't find where my mistake is?

1 view (last 30 days)
DS
DS on 21 Feb 2019
Answered: Takumi on 21 Feb 2019
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 Comment
Bob Thompson
Bob Thompson on 21 Feb 2019
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.

Sign in to comment.

Answers (1)

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

Categories

Find more on Linear Algebra 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!