Skip to content
DeepForgeby svx
All problems
HardLinear Algebrala-139

Rank-1 Approximation

Problem

Compute the best rank-1 approximation of a 2x2 matrix A using its dominant singular pair.

Form B = A^T A, take its largest eigenvalue lambda1 and a corresponding unit eigenvector v (positive convention), set sigma = sqrt(lambda1), u = A*v / sigma, and return sigma * u*v^T. Return the zero matrix if sigma is 0.

Hint

This is the Eckart-Young theorem for rank 1: keep only the leading singular triple.

Test cases

case 1
in: [[[3,0],[0,1]]]
expected: [[3,0],[0,0]]
case 2
in: [[[2,0],[0,0]]]
expected: [[2,0],[0,0]]
case 3
in: [[[1,1],[0,0]]]
expected: [[1,1],[0,0]]
case 4
in: [[[2,1],[1,2]]]
expected: [[1.5,1.5],[1.5,1.5]]
case 5
in: [[[0,0],[0,0]]]
expected: [[0,0],[0,0]]
Starter codePython
def rank1_approximation(A):
    # Your code here
    pass

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