Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
HW 4
  • Loading branch information
jjv14001 committed Oct 12, 2017
1 parent a821176 commit 67ddcc4
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions 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)

0 comments on commit 67ddcc4

Please sign in to comment.