MATLAB Answers

I can't find where my mistake is?

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

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

  0 Comments

Sign in to comment.

Sign in to answer this question.