Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-218

Characteristic Polynomial 3x3

Problem

Return the coefficients [1.0, b, c, d] of the characteristic polynomial of a 3x3 matrix:

lambda^3 - tr(A)*lambda^2 + c2*lambda - det(A)

where c2 = (tr(A)^2 - tr(A^2)) / 2. So b = -tr(A), c = c2, d = -det(A).

Hint

Newton's identities relate the power sums tr(A), tr(A^2) to the elementary symmetric coefficients.

Test cases

case 1
in: [[[1,0,0],[0,1,0],[0,0,1]]]
expected: [1,-3,3,-1]
case 2
in: [[[2,1,0],[0,3,1],[0,0,4]]]
expected: [1,-9,26,-24]
case 3
in: [[[1,2,3],[4,5,6],[7,8,9]]]
expected: [1,-15,-18,0]
case 4
in: [[[1,0,1],[0,1,0],[-1,0,1]]]
expected: [1,-3,4,-2]
Starter codePython
def char_poly_3x3(A):
    # Your code here
    pass

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