clear all, close all

format compact
format long

%A = laplacian2d(8);
%[n, ~] = size(A);

n = 64;
A = gensmspectr(n);

tol = 1.e-14;
rng(1);
x0 = rand(n, 1);

maxiter = 400;

q = 6.2;
[lambda1, x1, conv1] = myinversepower(A, x0, q, tol, maxiter);
[lambda2, x2, conv2] = myrayleigh(A, x0, q, tol, maxiter);

eigen = 6.;
abs(lambda1)
abserr = abs( eigen - abs(lambda1) )
abs(lambda2)
abserr = abs( eigen - abs(lambda2) )

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

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

semilogy(nps1, conv1, 'r.-');
grid on
hold on
semilogy(nps2, conv2, 'b.-');
legend('Inverse Power iterations', 'Rayleight quotient iterations')
xlabel('Iteration number');
ylabel('|Delta|');
title('Convergence of inverse power iteration process');
