% 
% test Jacobi method
%clear all;
f = who;
if length(strmatch('t',f,'exact')) == 0
    t = 1;
end
A = [10 -2 3  0;
     -1 11 -1 3;
      2 -1 10 -1;
      0  3 -1 8];
b = [6;25;-11;15];
xo = [0;0;0;0];
sln= A \b;
D = diag(A);
if (t == 1)
    T = diag(D)\(diag(D)-A);
end;
c = b ./D;
for k = 1:50
    if (t == 1)
        x = c + T * xo;
    else
        x = c + (xo - (A*xo)./D);   
    end
    err(k) = norm(x-sln);
    dif(k) = norm(x-xo);
    xo  = x;
end
figure(2);
clf;
semilogy(err,'b.-');
hold on;
semilogy(dif,'r.-');
title('Jacobi Iteration Errors','FontSize',18);
legend('Error in Solution','Solution Change in Each Iteration');
