Skip to Content

CHOLESKY

Overview

The CHOLESKY function computes the Cholesky decomposition of a Hermitian, positive-definite matrix. The Cholesky decomposition factorizes a matrix AA into the product A=LLA = LL^* (if lower-triangular) or A=UUA = U^*U (if upper-triangular), where LL is a lower-triangular matrix and UU is an upper-triangular matrix. This decomposition is widely used in numerical linear algebra for solving systems of equations, Monte Carlo simulations, and optimization problems. For more details, see the scipy.linalg.cholesky documentation.

This example function is provided as-is without any representation of accuracy.

Usage

To use the function in Excel:

=CHOLESKY(matrix, [lower])
  • matrix (2D list, required): Hermitian (symmetric if real) positive-definite matrix to decompose. Must be square (n x n).
  • lower (bool, optional, default=FALSE): If TRUE, returns the lower-triangular Cholesky factor LL such that A=LLA = LL^*. If FALSE, returns the upper-triangular factor UU such that A=UUA = U^*U.

The function returns a 2D array (matrix) containing the Cholesky factor, or a 2D array of strings with an error message if the input is invalid.

Examples

Example 1: Lower-triangular Cholesky of a real symmetric matrix

In Excel:

=CHOLESKY({4,12;-2,37}, TRUE)

Expected output:

2.00.0
-1.06.0

Example 2: Upper-triangular Cholesky of a real symmetric matrix

In Excel:

=CHOLESKY({4,12;-2,37}, FALSE)

Expected output:

2.06.0
0.01.0

Example 3: Lower-triangular Cholesky of a 3x3 matrix

In Excel:

=CHOLESKY({25,15,-5;15,18,0;-5,0,11}, TRUE)

Expected output:

5.00.00.0
3.03.00.0
-1.01.03.0

Example 4: Lower-triangular Cholesky of a positive-definite matrix with negative off-diagonal

In Excel:

=CHOLESKY({9,-6,3;-6,8,-2;3,-2,3}, TRUE)

Expected output:

3.00.00.0
-2.02.00.0
1.00.01.414214

Python Code

import numpy as np from scipy.linalg import cholesky as scipy_cholesky def cholesky(matrix, lower=False): """ Compute the Cholesky decomposition of a Hermitian, positive-definite matrix. Args: matrix: 2D list (square), Hermitian (symmetric if real) positive-definite matrix. lower: bool, optional (default: False). If True, return lower-triangular factor. Returns: 2D list (matrix) of Cholesky factor, or 2D list of str with error message if input is invalid. This example function is provided as-is without any representation of accuracy. """ # Validate input if not isinstance(matrix, list) or not matrix or not isinstance(matrix[0], list): return [["Error: Input must be a 2D list (matrix)"]] n = len(matrix) if any(len(row) != n for row in matrix): return [["Error: Matrix must be square (n x n)"]] try: arr = np.array(matrix, dtype=np.complex128) except Exception: return [["Error: Matrix must contain only numbers"]] try: result = scipy_cholesky(arr, lower=bool(lower)) except Exception as e: return [[f"Error: {str(e)}"]] # Convert result to 2D list of floats (rounded for Excel) result_list = result.tolist() for i in range(len(result_list)): for j in range(len(result_list[i])): if abs(result_list[i][j].imag) < 1e-12: result_list[i][j] = round(result_list[i][j].real, 6) else: result_list[i][j] = str(result_list[i][j]) return result_list

Live Notebook

Edit this function in a live notebook.

Live Demo

Last updated on