Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-124

Solve XA = B

Problem

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

Return X = B * inv(A) as a matrix of floats, or None if det(A) == 0.

Hint

Multiply on the right by the inverse of A, not the left.

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,6],[6,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_xa(A, B):
    # Your code here
    pass

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