diff --git a/Hilbert.py b/Hilbert.py index 721d2e3..28f8d68 100644 --- a/Hilbert.py +++ b/Hilbert.py @@ -1,8 +1,32 @@ -from scipy.linalg import invhilbert +from scipy.linalg import inv, hilbert, invhilbert +import numpy as np print("Inverse Hilbert Matrix n = 3: ") -invhilbert(3) +print(invhilbert(3),True) print("Inverse Hilbert Matrix n = 4: ") -invhilbert(4,True) +print(invhilbert(4,True)) print("Inverse Hilbert Matrix n = 5: ") -invhilbert(5,True) +print(invhilbert(5,True)) + + +def HilbertApprox(n,m): + h = hilbert(n) + h = h.round(m) +# for i in h: +# for j in i: +# j = round(j,m) +# j = round(j,m) +# [round(i,m) for i in h[0]] + print("For H(", n, ") rounded to ", m, "decimal places:") + print(inv(h).round(m)) + +HilbertApprox(3,2) +HilbertApprox(4,2) +HilbertApprox(5,2) +HilbertApprox(3,1) +HilbertApprox(4,1) +HilbertApprox(5,1) +#print(type(hilbert(2))) +#a = [1,3.004,5.2222] +#[round(i,2) for i in a] +#print(a)