TExcelTAD
Home › Numerical Methods › Inverse Iteration and Rayleigh Quotients

Inverse Iteration

Power iteration finds only the largest eigenvalue, and slowly if the next one is close. Applying power iteration to (A−sI)−1(A - sI)^{-1} instead finds the eigenvalue closest to a shift ss, and can converge very fast. Updating the shift at every step gives Rayleigh quotient iteration, which converges cubically for symmetric matrices.

Shift and invert

Av=λvA\mathbf{v} = \lambda\mathbf{v} implies (A−sI)−1v=1λ−sv(A - sI)^{-1}\mathbf{v} = \frac{1}{\lambda - s}\mathbf{v}. The eigenvalue of AA nearest ss becomes the largest eigenvalue of (A−sI)−1(A - sI)^{-1}, so power iteration on it converges to that eigenvector with rate

∣λnearest−sλsecond nearest−s∣,\left\lvert\frac{\lambda_{\text{nearest}} - s}{\lambda_{\text{second nearest}} - s}\right\rvert,

which is small when ss is a good guess. We never form the inverse: factor A−sI=LUA - sI = LU once and solve one system per step.

python · try it yourself
import numpy as np
import scipy.linalg as sla

rng = np.random.default_rng(61)
Q, _ = np.linalg.qr(rng.normal(size=(40, 40)))
lams = np.r_[3.0, 3.2, np.linspace(-10, 2, 19), np.linspace(5, 10, 19)]
A = Q @ np.diag(lams) @ Q.T                     # symmetric, eigenvalues include 3 and 3.2

s = 2.9                                         # shift near 3
lu = sla.lu_factor(A - s * np.eye(40))
x = rng.normal(size=40)
for k in range(1, 9):
    x = sla.lu_solve(lu, x)
    x /= np.linalg.norm(x)
    print(f"k = {k}: Rayleigh quotient {x @ A @ x:.14f}")
print("predicted rate:", round(abs(3.0 - s) / min(abs(l - s) for l in lams if l != 3.0), 4), "per step for the vector; squared for the Rayleigh quotient")
k = 1: Rayleigh quotient 2.99907073268261
k = 2: Rayleigh quotient 3.00006638643713
k = 3: Rayleigh quotient 3.00000829589685
k = 4: Rayleigh quotient 3.00000092708005
k = 5: Rayleigh quotient 3.00000010304934
k = 6: Rayleigh quotient 3.00000001145033
k = 7: Rayleigh quotient 3.00000000127226
k = 8: Rayleigh quotient 3.00000000014137
predicted rate: 0.3333 per step for the vector; squared for the Rayleigh quotient

Rayleigh quotient iteration

If we use the current Rayleigh quotient as the shift at every step, the shift gets better as the vector does. For symmetric matrices the convergence is cubic: the number of correct digits roughly triples per step. The price: a new factorization each step, since the shift changes.

python · try it yourself
import numpy as np

rng = np.random.default_rng(61)
Q, _ = np.linalg.qr(rng.normal(size=(40, 40)))
lams = np.r_[3.0, 3.2, np.linspace(-10, 2, 19), np.linspace(5, 10, 19)]
A = Q @ np.diag(lams) @ Q.T

x = Q[:, 0] + 0.02 * rng.normal(size=40)          # rough approximation of the eigenvector
x /= np.linalg.norm(x)
for k in range(1, 5):
    rho = x @ A @ x
    print(f"k = {k}: shift {rho:.16f}, error {abs(rho - 3.0):.1e}")
    x = np.linalg.solve(A - rho * np.eye(40), x)
    x /= np.linalg.norm(x)
k = 1: shift 2.9848539169591461, error 1.5e-02
k = 2: shift 3.0000000244592337, error 2.4e-08
k = 3: shift 3.0000000000000027, error 2.7e-15
k = 4: shift 3.0000000000000009, error 8.9e-16

Notice that A−ρIA - \rho I becomes nearly singular as ρ\rho approaches the eigenvalue. That is harmless: the solve's error points mostly along the eigenvector we want, and normalization removes the huge scale.

Uses

  • Computing an eigenvector once an eigenvalue estimate is known (the standard way LAPACK gets selected eigenvectors).
  • Interior eigenvalues of large sparse matrices with shift-invert Krylov methods: eigsh(A, k, sigma=s).
  • Finding the vibration mode of a structure nearest a forcing frequency.

In software

  • scipy.sparse.linalg.eigsh(A, k=3, sigma=2.9) uses shift-invert mode with a sparse LU of A−σIA - \sigma I and returns the 3 eigenvalues nearest 2.9.
  • scipy.linalg.eigh(A, subset_by_value=(a, b)) returns only the eigenvalues in an interval.

Exercises

Exercise 1: Which eigenvalue?

AA has eigenvalues −4,1,2,7-4, 1, 2, 7. Inverse iteration with shift s=1.6s = 1.6 converges to which, and at what rate?

Answer

λ=2\lambda = 2, rate 0.40.6=23\frac{0.4}{0.6} = \frac{2}{3}.

Solution

Distances to ss: 5.6,0.6,0.4,5.45.6, 0.6, 0.4, 5.4. The nearest is 22 (0.40.4), the next is 11 (0.60.6).

Exercise 2: The smallest eigenvalue

How do you find the eigenvalue of smallest magnitude with inverse iteration?

Answer

Use shift s=0s = 0: power iteration on A−1A^{-1}.

Solution

The largest eigenvalue of A−1A^{-1} is 1λmin⁡\frac{1}{\lambda_{\min}} where λmin⁡\lambda_{\min} is the eigenvalue of AA of smallest magnitude.

Exercise 3: Shift-invert in SciPy (code)

Find the 3 eigenvalues of the lesson's matrix nearest 2.92.9 with scipy.sparse.linalg.eigsh in shift-invert mode.

Answer

22, 33 and 3.23.2.

Solution
python · try it yourself
import numpy as np
from scipy.sparse.linalg import eigsh
rng = np.random.default_rng(61)
Q, _ = np.linalg.qr(rng.normal(size=(40, 40)))
A = Q @ np.diag(np.r_[3.0, 3.2, np.linspace(-10, 2, 19), np.linspace(5, 10, 19)]) @ Q.T
vals = eigsh(A, k=3, sigma=2.9, return_eigenvectors=False)
print(np.round(np.sort(vals), 4))
[2.  3.  3.2]

Test yourself

Inverse iteration with shift ss converges to the eigenvalue…

  1. largest in magnitude
  2. closest to ss
  3. smallest in magnitude
  4. farthest from ss

For symmetric matrices, Rayleigh quotient iteration converges…

  1. linearly
  2. quadratically
  3. cubically
  4. not at all

Inverse iteration should be implemented by…

  1. computing (A−sI)−1(A - sI)^{-1} explicitly
  2. factoring A−sIA - sI once and solving each step
  3. using the determinant
  4. power iteration on AA