You are on page 1of 1

function [x1, n, err]=jacobi(A,b,x,tol)

n=0;
L=tril(A,-1); D=diag(diag(A)); U=triu(A,1);
B=-inv(D)*(L+U); d=inv(D)*b;
x1=B*x+d;
if max(abs(eig(B)))>1
disp('o m�todo n�o converge')
disp('------------------------')
else
while norm(x-x1,inf)>tol
x=x1; x1=B*x+d;
n=n+1;
end
end
err=norm(x-x1,inf);

You might also like