Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-286

Block Diagonal Eigenvalues

Problem

Compute the eigenvalues of a block diagonal matrix given as a list of diagonal blocks.

Each block is either 1x1 (its scalar) or 2x2, solved from lambda^2 - tr*lambda + det = 0. Return all eigenvalues sorted ascending, or None if any 2x2 block has complex eigenvalues (negative discriminant).

Hint

Eigenvalues of a block diagonal matrix are the union of the blocks' eigenvalues.

Test cases

case 1
in: [[[[2,0],[0,3]],[[4]]]]
expected: [2,3,4]
case 2
in: [[[[1,1],[0,2]]]]
expected: [1,2]
case 3
in: [[[[0,-1],[1,0]]]]
expected: null
case 4
in: [[[[5]]]]
expected: [5]
case 5
in: [[[[3,0],[0,3]],[[-1]]]]
expected: [-1,3,3]
Starter codePython
def block_diagonal_eigenvalues(blocks):
    # Your code here
    pass

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