Skip to content
DeepForgeby svx
All problems
HardLinear Algebrala-091

Solve 3x3 System by Gaussian Elimination

Problem

Solve the 3x3 linear system A*x = b using Gaussian elimination with partial pivoting.

Return x as a list of floats, or None if A is singular (some pivot has magnitude below 1e-12).

Hint

Eliminate below each pivot, then back-substitute from the last row up.

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 solve_3x3(A, b):
    # Your code here
    pass

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