Free cookie consent management tool by TermsFeed Cholesky decomposition | Pythontic.com

Cholesky decomposition

Overview:

  • The Cholesky decomposition of a square matrix is given by the product of its lower or upper triangular matrix and its transpose.
  • The chole() function of the NumPy linear module returns the Cholesky decomposition of a given square matrix.

Example:

# Example Python program that provides the Cholsky decomposition
# of a square matrix

import numpy

# Create a matrix with the same number of rows and columns
matrix_square = numpy.ndarray(shape = (4, 4))

# Make the matrix a lower triangular one
matrix_square[0][0] = 1
matrix_square[0][1] = 1
matrix_square[0][2] = 1
matrix_square[0][3] = 1

matrix_square[1][0] = 0
matrix_square[1][1] = 1
matrix_square[1][2] = 1
matrix_square[1][3] = 1

matrix_square[2][0] = 0
matrix_square[2][1] = 0
matrix_square[2][2] = 1
matrix_square[2][3] = 1

matrix_square[3][0] = 0
matrix_square[3][1] = 0
matrix_square[3][2] = 0
matrix_square[3][3] = 1

print("Square matrix:")
print(matrix_square)
print(type(matrix_square[0][0]))

# Compute Cholesky decomposition
cd = numpy.linalg.cholesky(matrix_square)
print("Cholesky decomposition of the square matrix:")
print(cd)

Output:

Cholesky decomposition of the square matrix:

[[1. 0. 0. 0.]

 [0. 1. 0. 0.]

 [0. 0. 1. 0.]

 [0. 0. 0. 1.]]

 


Copyright 2025 © pythontic.com