Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-208

LDL^T Decomposition 2x2

Problem

Compute the LDL^T decomposition A = L*D*L^T of a symmetric 2x2 matrix, with unit lower triangular L and diagonal D.

Use L[1][0] = A[1][0] / A[0][0] and D[1][1] = A[1][1] - L[1][0]^2 * A[0][0]. Return [L, D].

Hint

LDL^T avoids square roots; D can have negative entries for indefinite matrices.

Test cases

case 1
in: [[[4,2],[2,3]]]
expected: [[[1,0],[0.5,1]],[[4,0],[0,2]]]
case 2
in: [[[1,0],[0,1]]]
expected: [[[1,0],[0,1]],[[1,0],[0,1]]]
case 3
in: [[[9,6],[6,5]]]
expected: [[[1,0],[0.6666666666666666,1]],[[9,0],[0,1]]]
case 4
in: [[[2,1],[1,2]]]
expected: [[[1,0],[0.5,1]],[[2,0],[0,1.5]]]
Starter codePython
def ldl_decompose_2x2(A):
    # Your code here
    pass

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