Skip to content
DeepForgeby svx
All problems
HardLinear Algebrala-048

Cholesky Decomposition

Problem

Compute the lower-triangular Cholesky factor L of a symmetric positive definite matrix A, so that A = L*L^T.

Use L[i][j] = (A[i][j] - sum_k L[i][k]*L[j][k]) / L[j][j] for i > j, and the square root of the reduced diagonal for i == j.

Hint

The inner sum runs over columns k < j; divide by the diagonal entry L[j][j].

Test cases

case 1
in: [[[4,2],[2,3]]]
expected: [[2,0],[1,1.4142135623730951]]
case 2
in: [[[25,15,5],[15,18,0],[5,0,11]]]
expected: [[5,0,0],[3,3,0],[1,-1,3]]
case 3
in: [[[1,0],[0,1]]]
expected: [[1,0],[0,1]]
case 4
in: [[[9,0],[0,16]]]
expected: [[3,0],[0,4]]
Starter codePython
def cholesky(A):
    # Your code here
    pass

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