All problems
Cramer's Rule 3x3
Problem
Solve the 3x3 linear system A*x = b using Cramer's rule:
x[i] = det(A_i) / det(A)
where A_i is A with column i replaced by b. Return x as a list of floats, or None if det(A) == 0.
Hint
Replace one column at a time and take determinant ratios.
Test cases
case 1
in: [[[1,0,0],[0,1,0],[0,0,1]],[1,2,3]]
expected: [1,2,3]
case 2
in: [[[2,1,-1],[-3,-1,2],[-2,1,2]],[8,-11,-3]]
expected: [2,3,-1]
case 3
in: [[[1,2,3],[0,1,4],[5,6,0]],[5,6,5]]
expected: [13,-10,4]
case 4
in: [[[1,2,3],[4,5,6],[7,8,9]],[1,1,1]]
expected: null
Starter codePython
def cramer_3x3(A, b):
# Your code here
pass4 test cases · run your code against them in the editor