Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-260

Perron Eigenvector Sign Check

Problem

Run power iteration on A starting from the all-ones vector for num_iterations steps, then return True only if every component of the final unit vector is positive (greater than 1e-9).

For positive matrices the Perron-Frobenius theorem guarantees a positive dominant eigenvector; other matrices may fail this test.

Hint

Sign flips between iterations indicate that the dominant eigenvalue is negative or the matrix is not positive.

Test cases

case 1
in: [[[2,1],[1,2]],20]
expected: true
case 2
in: [[[1,1],[1,1]],10]
expected: true
case 3
in: [[[1,0],[0,-2]],3]
expected: false
case 4
in: [[[0,1],[1,0]],9]
expected: true
Starter codePython
def perron_eigenvector_sign(A, num_iterations):
    # Your code here
    pass

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