Skip to content
DeepForgeby svx
All problems
HardLinear Algebrala-132

Spectral Norm by Power Iteration

Problem

Estimate the spectral norm ||A||_2 of matrix A using power iteration on B = A^T A.

Start with v = [1.0, ..., 1.0]. Each iteration computes w = B*v and sets v = w / ||w||_2. After num_iterations, return sqrt(v . (B*v)). Return 0.0 if a normalization step hits the zero vector.

Hint

||A||_2 is the square root of the largest eigenvalue of A^T A.

Test cases

case 1
in: [[[2,0],[0,1]],10]
expected: 1.9999999999993179
case 2
in: [[[1,2],[3,4]],20]
expected: 5.464985704219043
case 3
in: [[[0]],1]
expected: 0
case 4
in: [[[1,0],[0,1]],5]
expected: 1
Starter codePython
def spectral_norm(A, num_iterations):
    # Your code here
    pass

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