
%% Setup

n = 100;
[Q,~] = qr(rand(n));
A = Q * diag(1:n) * Q';

%% Power iteration

x = rand(n, 1);
for i = 1:20
    x = A*x;
    x = x / norm(x);
end

evPower = x' * A * x;
errorPower = abs(evPower - n)/n

%% Inverse iteration

x = rand(n, 1);
for i = 1:20
    x = A \ x;
    x = x / norm(x);
end

evInverse = x' * A * x;
errorInverse = abs(evInverse - 1)/1