Skip to content
DeepForgeby svx
All problems
HardLinear Algebrala-090

Matrix Equation AX=B

Problem

Solve the matrix equation A*X = B for X, where A and B are 2x2 matrices and A is invertible.

Return X = inv(A)*B, or None if det(A) == 0.

Hint

X has the same number of columns as B; invert A once and multiply.

Test cases

case 1
in: [[[1,0],[0,1]],[[1,2],[3,4]]]
expected: [[1,2],[3,4]]
case 2
in: [[[2,0],[0,3]],[[2,4],[9,12]]]
expected: [[1,2],[3,4]]
case 3
in: [[[1,2],[3,4]],[[1,0],[0,1]]]
expected: [[-2,1],[1.5,-0.5]]
case 4
in: [[[1,2],[2,4]],[[1,1],[1,1]]]
expected: null
Starter codePython
def solve_axb(A, B):
    # Your code here
    pass

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