All problems
Cramer's Rule 2x2
Problem
Solve the 2x2 linear system A*x = b using Cramer's rule.
x = det(Ax) / det(A) and y = det(Ay) / det(A), where Ax replaces column 0 of A with b and Ay replaces column 1. Return [x, y] as floats, or None if det(A) == 0.
Hint
Compute the three 2x2 determinants with the cross formula.
Test cases
case 1
in: [[[2,1],[1,3]],[5,10]]
expected: [1,3]
case 2
in: [[[1,2],[3,4]],[5,11]]
expected: [1,2]
case 3
in: [[[1,2],[2,4]],[3,6]]
expected: null
case 4
in: [[[3,0],[0,2]],[6,4]]
expected: [2,2]
Starter codePython
def cramer_2x2(A, b):
# Your code here
pass4 test cases · run your code against them in the editor