Skip to main content

Power method pseudo-code

Short answer

Power method: start with non-zero vector x, iterate y = A*x, lambda = largest component of y, x = y/lambda. Repeat until |lambda - lambda_old| < tolerance. Output dominant eigenvalue lambda and eigenvector x.

Write a pseudo-code (algorithm) to determine the largest (dominant) eigenvalue and the corresponding eigenvector of a square matrix using the Power Method.

The power method finds the dominant eigenvalue (largest in magnitude) and its eigenvector. Repeated multiplication A·x makes the vector turn toward the dominant eigenvector, and the scale factor approaches the eigenvalue.

Pseudo-code

Algorithm: Power method
Input : n, matrix A[n][n], initial vector x[n] (non-zero,
        e.g. all 1), tolerance e, max iterations N
Output: dominant eigenvalue lambda, eigenvector x

1.  Read n, A, x, e, N
2.  Set lambda_old = 0, k = 1
3.  Repeat steps 4 to 11 while k <= N
4.      y = A * x            // y[i] = sum_j A[i][j]*x[j]
5.      lambda = element of y with largest absolute value
6.      If lambda = 0 then
            print "Zero eigenvalue; try another x"; stop
7.      For i = 1 to n do
            x[i] = y[i] / lambda     // scale
        End for
8.      If |lambda - lambda_old| < e then
9.          print "Dominant eigenvalue =", lambda
10.         print "Eigenvector =", x
            stop
        End if
11.     lambda_old = lambda
        k = k + 1
12. End repeat
13. Print "Not converged in N iterations"
14. Stop

Notes

  • Convergence rate depends on the ratio |λ2/λ1| of the two largest eigenvalues; the smaller the ratio, the faster.
  • The starting vector must have a component along the dominant eigenvector.
  • Scaling by the largest component keeps numbers from overflowing.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Numerical Method chapter 3 questions →