Skip to content
DeepForgeby svx
All problems
HardLinear Algebrala-047

LU Decomposition (Doolittle)

Problem

Factor square matrix A as A = L*U using Doolittle's method without pivoting.

L is unit lower triangular (ones on the diagonal) and U is upper triangular. Return [L, U] with entries as floats. You may assume no zero pivot is encountered.

Hint

Compute U[i][j] with the current row of L, then the multipliers L[j][i] below it.

Test cases

case 1
in: [[[2,1],[4,3]]]
expected: [[[1,0],[2,1]],[[2,1],[0,1]]]
case 2
in: [[[4,3],[6,3]]]
expected: [[[1,0],[1.5,1]],[[4,3],[0,-1.5]]]
case 3
in: [[[1,0,0],[0,1,0],[0,0,1]]]
expected: [[[1,0,0],[0,1,0],[0,0,1]],[[1,0,0],[0,1,0],[0,0,1]]]
case 4
in: [[[2,1,1],[4,3,3],[8,7,9]]]
expected: [[[1,0,0],[2,1,0],[4,3,1]],[[2,1,1],[0,1,1],[0,0,2]]]
Starter codePython
def lu_decompose(A):
    # Your code here
    pass

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