All problems
Eigenvalues of Triangular Matrix
Problem
Return the eigenvalues of a square triangular matrix A (upper or lower triangular).
The eigenvalues are exactly the diagonal entries, returned in order as a list.
Hint
The characteristic polynomial of a triangular matrix is the product of (lambda - A[i][i]).
Test cases
case 1
in: [[[2,5,7],[0,3,9],[0,0,4]]]
expected: [2,3,4]
case 2
in: [[[1,0,0],[2,3,0],[4,5,6]]]
expected: [1,3,6]
case 3
in: [[[5,0],[0,7]]]
expected: [5,7]
case 4
in: [[[1,0,0],[0,1,0],[0,0,1]]]
expected: [1,1,1]
Starter codePython
def triangular_eigenvalues(A):
# Your code here
pass4 test cases · run your code against them in the editor