Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-084

Normalized Eigenvector 2x2

Problem

Return a unit eigenvector of the 2x2 matrix A for the given eigenvalue lam.

Form M = A - lam*I. Take the first row [a, b] of M with a nonzero entry, use [-b, a], and normalize it to unit L2 length. If M is the zero matrix, return [1.0, 0.0].

Hint

Any vector in the null space of A - lam*I is an eigenvector for lam.

Test cases

case 1
in: [[[2,0],[0,3]],2]
expected: [-1,0]
case 2
in: [[[4,1],[2,3]],5]
expected: [-0.7071067811865475,-0.7071067811865475]
case 3
in: [[[4,1],[2,3]],2]
expected: [-0.4472135954999579,0.8944271909999159]
case 4
in: [[[1,0],[0,1]],1]
expected: [1,0]
Starter codePython
def normalized_eigenvector(A, lam):
    # Your code here
    pass

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