Skip to content
DeepForgeby svx
All problems
HardLinear Algebrala-044

Inverse 3x3 via Adjugate

Problem

Compute the inverse of a 3x3 matrix A using the adjugate formula:

inv(A) = adj(A) / det(A)

where det(A) is the cofactor expansion along the first row. Return None if det(A) == 0.

Hint

det(A) equals the dot product of the first row of A with the first row of the cofactor matrix.

Test cases

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

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