A = ddbucky();
[n, ~] = size(A);

tol = 1.e-10;
itermax = 3500;

x = ones(n, 1);
b = rand(n, 1);

[x1, conv1] = myjacobi(A, b, x, tol, itermax);
[x2, conv2] = myjacobi2(A, b, tol, itermax);
    
sigma = jacobitheor(A);

niter1 = length(conv1);
nps1 = 1:niter1;

niter2 = length(conv2);
nps2 = 1:niter2;

semilogy(nps1, conv1, 'r.-');
grid on
hold on
semilogy(nps2, conv2, 'b.-');
semilogy(nps1, conv1(1)/4*exp(sigma*nps1), '--')
legend('Jacobi iterations', 'Jacobi iterations improved', 'theory');
xlabel('Iteration number');
ylabel('|A*x - b|^2');
title('Convergence of Jacobi iteration process');


