Skip to content
DeepForgeby svx
All problems
HardLinear Algebrala-050

Power Iteration Dominant Eigenvalue

Problem

Estimate the dominant eigenvalue and eigenvector of matrix A with power iteration.

Start from v = [1.0, ..., 1.0]. Each of the num_iterations iterations performs: w = A*v, lam = ||w||_2, v = w / lam. Return [lam, v] after the final iteration.

Hint

The norm of w is the current eigenvalue estimate, so reuse it to normalize.

Test cases

case 1
in: [[[2,0],[0,1]],10]
expected: [1.9999971389859181,[0.9999995231631829,0.0009765620343390458]]
case 2
in: [[[4,2],[1,3]],5]
expected: [5.0075749527374835,[0.8930477200189154,0.4499619648026008]]
case 3
in: [[[3]],4]
expected: [3,[1]]
case 4
in: [[[5,0,0],[0,2,1],[0,1,2]],8]
expected: [4.997495643621757,[0.999718008333068,0.016791423622843537,0.016791423622843537]]
Starter codePython
def power_iteration(A, num_iterations):
    # Your code here
    pass

4 test cases · run your code against them in the editor