0% found this document useful (0 votes)
183 views1 page

Jacobi Method and Asymptotic Error

The Jacobi method is used to estimate the solution x in a matrix equation Ax=b. The function iterates until a specified tolerance is reached. However, if the equation is ill-conditioned, the program can get stuck in an infinite loop without converging to a solution. The function calculates the asymptotic error constant to analyze the rate of convergence.

Uploaded by

api-548288377
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
183 views1 page

Jacobi Method and Asymptotic Error

The Jacobi method is used to estimate the solution x in a matrix equation Ax=b. The function iterates until a specified tolerance is reached. However, if the equation is ill-conditioned, the program can get stuck in an infinite loop without converging to a solution. The function calculates the asymptotic error constant to analyze the rate of convergence.

Uploaded by

api-548288377
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

%{

Jacobian method to estimate x in matrix equation Ax=b. This function will


run until a specified tolerance is reached. This has a drawback that
the program can be stuck in an infinite loop if the equation is ill
conditioned.

Owen Blair
University of Idaho
%}
function [x] = Jacobi(A,b,x_i,tol)

[~,n]=size(A);
disp(n);
N=1;
Const_jac=0;
error_jac=zeros(1,1);
xk=0;
xk1=0;
xk2=0;
x=x_i*ones(1,n);

while 1
%Debug for loop
%fprintf('Iteration %d\n', N);
xold=x;
for i=1:n
sigma=0;
for j=1:n
if j~=i
sigma=sigma+A(i,j)*x(j);
end
end

x(i)=(1/A(i,i))*(b(i)-sigma);
end
error_jac(N)=max(max(abs(xold-x)));

N=N+1;
if max(max(abs(xold-x))) < tol
break;
end
%Save the last two numbers
xk2=xk1;
xk1=xk;
xk=x;
%Calculate Asymptotic error constant
Const_jac=(max(abs(xk - xk1)))/(max(abs(xk1 - xk2)));
end
fprintf('Error limit reached at step %d\nThe asymptotic error constant is
%d',N,Const_jac);
semilogy(error_jac);
%disp(error_jac);
%disp(Const_jac);
end

You might also like