problemAINumerics
Make power iteration converge on a tied pair
Power iteration multiplies a vector by again and again and finds the eigenvalue of largest magnitude. The matrix above has two, and , of the same magnitude, and the iterate swaps its two entries every step forever. Write shifted_power so that the shift breaks the tie: iterate with , whose eigenvalues are .
Open in the workbenchDownload .vivOutputs below are from the site build’s run; Run all runs it again in your browser.
Look inside this program
- Atlas
The program’s map: every function and which calls which.
There’s no recorded run of this program yet.
Write in the eigenvectors, . After steps : the two parts stay the same size, and the sign of one flips each step. From the normalized iterate alternates between and , and its Rayleigh quotient is 1.101, which is neither eigenvalue.
has the same eigenvectors, with eigenvalues and . With those are 3 and , so the part wins by a factor of 3 per step; with they are 1 and , and wins. The Rayleigh quotient of the original then gives the eigenvalue itself.
The second matrix, , has
eigenvalues , again a tie. The expected vectors are
numpy.linalg.eigh's (posts/refs/make-power-iteration-converge-on-a-tied-pair.py),
signed so that the first entry is positive; the function must return its
vector signed the same way.
Your task
Write these 2 functions:
shifted_power(A: Arr, s, iters)- The unit vector power iteration with A + sI reaches after
iterssteps from (1, 0.3), signed so its first entry is positive. As written it ignores the shift s. rayleigh(A: Arr, v: Arr)- The Rayleigh quotient v^{\mathsf T} A v of a unit vector v.
Make these tests pass 4 of 4 fail
- shift +1 finds eigenvalue 2, vector (1, 1) / sqrt 2 assert_near: |0.957826 - 0.707107| = 0.25072 > 1e-12 (and 2 more) (fails)
- shift -1 finds eigenvalue -2, vector (1, -1) / sqrt 2 assert_near: |0.957826 - 0.707107| = 0.25072 > 1e-12 (and 2 more) (fails)
- on [[1, 2], [2, -1]] shift +1 finds sqrt 5 = 2.2360680 with numpy's vector assert_near: |0.957826 - 0.850651| = 0.107175 > 1e-12 (and 2 more) (fails)
- and shift -1 finds -sqrt 5 assert_near: |0.957826 - 0.525731| = 0.432095 > 1e-12 (and 2 more) (fails)
Printed