Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-117

Rayleigh Quotient

Problem

Compute the Rayleigh quotient of matrix A with respect to nonzero vector v:

R(A, v) = (v . (A*v)) / (v . v)

Return None if v is the zero vector.

Hint

For an eigenvector the Rayleigh quotient equals its eigenvalue.

Test cases

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

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