[Math] Inverse Power Iteration converges to largest eigenvalue instead of smallest

eigenvalues-eigenvectorsMATLAB

I am trying to write a Matlab function that takes a matrix and an iteration count and performs inverse power iteration to output the smallest eigenvalue. The problem is, as k increases, the function converges to the largest eigenvalue of A instead of the smallest. My code is:

function eigval = invpowerit (A, k, start)
  if ~exist('start', 'var')
    start = ones(size(A, 1), 1);
  end
  eigvec = start;
  for n = 1:k
    w = A\eigvec;
    normw = norm(w);
    eigvec = w/normw;
  end
  eigval = 1/normw;

I can't figure out where I have applied the method incorrectly.

Best Answer

Your are unlucky with your choice of starting vector, $(1,1)^T$. This happens to be an eigenvector of $\begin{pmatrix} 3 & 1 \\ 1 & 3 \end{pmatrix}$, so the iteration is stuck in that eigenspace and returns the corresponding eigenvalue ($4$), regardless of what other eigenvalues the matrix may have.

To avoid this issue, begin with a random vector: start = rand(size(A, 1), 1);