This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

← Posts

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 .

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 iters steps 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

v_plain: [0.957826, 0.287348]
1.10092
shifted_eigs: [3, -1, 1, -3]

Solutions 0

No solutions posted yet. Press Solve it on the card to edit the program there.

Checked when the site was built: 0 of 4 tests passed (4 left to solve), in under 0.1 s. Download 2026-09-25-make-power-iteration-converge-on-a-tied-pair.viv