A740 of 56
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

A7 · Lesson 40 · Lab: eigenvalues in code

Computing eigenvalues, steady states, modes and e^{At}

No formula gives the eigenvalues of a large matrix: for 5 × 5 and up, the characteristic polynomial has no solution in radicals, and finding its roots numerically is a poor method anyway. Libraries use iterations instead. In this lab you'll write the simplest one, power iteration, and watch it converge at the rate the eigenvalues set. Then you'll put library eigensolvers to work on lessons 33 to 39: a channel's long-run state, the three normal modes of a chain of coupled tanks, and the matrix exponential, computed so that it works even for the defective matrices eigenvectors can't handle.

  • Power iteration multiplies a vector by A over and over. The part along the top eigenvector grows fastest, and the rest shrinks by |λ2/λ1| each step.
  • The curve is the error after k steps, rk, for the ratio r you set. The readout counts the steps to reach 10−10.
  • Push r toward 1, two nearly equal eigenvalues, and convergence slows to a crawl.

Predict

Power iteration runs on a symmetric matrix with eigenvalues 4.73, 3 and 1.27. By what factor does the error in the Rayleigh-quotient estimate of the top eigenvalue shrink per step?

Name it

Power iteration

Start from almost any 𝐱 and repeat: 𝐱←A𝐱, then divide by |𝐱| so the numbers stay finite. Writing the start in eigenvectors, Ak𝐱=c1λ1k𝐯1+c2λ2k𝐯2+⋯, so the direction approaches 𝐯1 with error shrinking like |λ2/λ1|k. The Rayleigh quotient 𝐱TA𝐱 (with |𝐱|=1) estimates λ1. Production eigensolvers use the QR algorithm, a refined relative of this idea.

Library calls

  • np.linalg.eig(A) returns eigenvalues and eigenvector columns, complex if necessary, in no particular order.
  • np.linalg.eigh(S) is for symmetric matrices: real eigenvalues in increasing order and orthonormal eigenvectors, faster and more accurate.

The matrix exponential by scaling and squaring

eA=XeΛX−1 fails for defective matrices and loses accuracy when X is ill conditioned. The robust method uses the series, made safe by scaling and squaring: divide A by 2s until its norm is below about 1, sum a few series terms (they now shrink fast), then square the result s times, since eA=(eA/2s)2s. Library versions refine this with Padé approximations.

Worked example

How many steps does power iteration need on [210131014]?

Show the solution
  1. Eigenvalues. They are 3+3=4.732, 3 and 3−3=1.268.
  2. Convergence rate. The Rayleigh quotient's error shrinks per step by (34.732)2=0.402
  3. Track the error. Starting from (1,1,1), the error is 0.105 after one step, 0.0024 after five, and below 10−10 after 24, where 0.40224×0.26≈10−10

Answer 24 steps bring the error below 10−10.

Worked example

Three identical LC tanks in a row are each coupled to their neighbors with c = 0.1, and each has k = 1. What are the mode frequencies?

Show the solution
  1. Stiffness matrix. K=[k+c−c0−ck+2c−c0−ck+c]
  2. Mode frequencies. The eigenvalues are k, k+c and k+3c, so the mode frequencies, in rad/s, are 1=11.1=1.04881.3=1.1402
  3. Mode shapes. The slowest mode swings all three tanks together, (1,1,1); the middle one has the ends opposed and the center still, (1,0,−1); the fastest has the center against both ends, (1,−2,1).

Answer 1, 1.0488 and 1.1402 rad/s.

Check

A power iteration's error shrinks by 0.8 per step. How many steps take it from 1 to below 10−10?

Check

Three tanks in a row have k = 1 and coupling c = 0.05. What is the highest mode frequency?

Check

Write power(A, steps) returning the Rayleigh-quotient estimate of the largest eigenvalue after steps iterations from (1,1,…,1). Set lam = power(M, 60) for the matrix in the starter.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

A three-state channel moves between states with the Markov matrix in the starter (its columns sum to 1). Use np.linalg.eig to find the steady state, scaled so its entries sum to 1, and set p.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Build K for three tanks in a row with k = 1 and coupling c = 0.15, and set w to the mode frequencies in increasing order, using np.linalg.eigh.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write expm(A) by scaling and squaring: choose s so that A/2s has norm below 1, sum 20 terms of the series, then square s times. Set E1 = expm(np.array([[0, -np.pi], [np.pi, 0]])) and E2 = expm(np.array([[1.0, 1], [0, 1]])).

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why does power iteration find the largest eigenvalue, and what makes it slow?

Practice

Keep practicing

5 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.