-
Notifications
You must be signed in to change notification settings - Fork 0
/
CDHM_numpy.py
19 lines (14 loc) · 775 Bytes
/
CDHM_numpy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# This program prints the the lower-triangular matrix in Cholesky decomposition of -
# a Hilbert matrix of any given order.
# Code by: Arash Ashrafzadeh
# Homepage: https://arashmath.github.io/
# Importing necessary libraries
from numpy.linalg import cholesky # To perform matrix decomposition
from scipy.linalg import hilbert # To create the Hilbert matrix
# Inputting the order of the Hilbert matrix
n = int(input(" Please enter the order of Hilbert matrix: "))
# Printing the lower-triangular matrix in Cholesky decomposition for Hilbert matrix
print(cholesky(hilbert(n)))
# Lines 12 & 15 can be merged into one line as the following (but it violates the clean, readable coding
# # paradigms I guess! So it's not recommended).
# print(cholesky(hilbert(int(input()))))