Sample Code

import numpy as np # 1. Define a symmetric, positive-definite matrix A # (Cholesky decomposition requires the matrix to meet these conditions) A = np.array([[4, 12, -16], [12, 37, -53], [-16, -53, 98]], dtype=float) # 2. Compute the Cholesky decomposition # This returns the lower triangular matrix L L = np.linalg.cholesky(A) # 3. Verify the result by reconstructing A (L multiplied by its transpose) A_reconstructed = np.dot(L, L.T) # Print results print("Original Matrix A:") print(A) print("\nLower Triangular Matrix L:") print(L) print("\nReconstructed Matrix (L * L.T):") print(A_reconstructed) # Check if the reconstruction is matching the original matrix print("\nIs the reconstruction successful?", np.allclose(A, A_reconstructed))