All problems
Forward and Back Substitution Solve
Problem
Solve the system L*U*x = b, where L is unit lower triangular and U is upper triangular.
First solve L*y = b by forward substitution, then solve U*x = y by back substitution. Return x as a list of floats.
Hint
Forward substitution uses only previously computed y values; back substitution mirrors it.
Test cases
case 1
in: [[[1,0],[0,1]],[[2,1],[0,4]],[5,8]]
expected: [1.5,2]
case 2
in: [[[2,0],[1,3]],[[1,2],[0,1]],[2,7]]
expected: [-3,2]
case 3
in: [[[1,0,0],[2,1,0],[3,4,1]],[[1,2,3],[0,2,1],[0,0,5]],[6,15,35]]
expected: [1,1,1]
case 4
in: [[[1,0],[0,1]],[[1,0],[0,1]],[3,-4]]
expected: [3,-4]
Starter codePython
def lu_solve(L, U, b):
# Your code here
pass4 test cases · run your code against them in the editor