Skip to content
Permalink
238fa7537c
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
61 lines (57 sloc) 1.47 KB
from scipy.linalg import *
import numpy as np
#print("Inverse Hilbert Matrix n = 3: ")
#print(invhilbert(3))
#print("Matrix Multiplication H(3) * H^-1(3)")
#print(hilbert(3).dot(invhilbert(3)))
#print("Inverse Hilbert Matrix n = 4: ")
#print(invhilbert(4,True))
#print("Matrix Multiplication H(4) * H^-1(4)")
#print(hilbert(4).dot(invhilbert(4)))
#print("Inverse Hilbert Matrix n = 5: ")
#print(invhilbert(5,True))
#print("Matrix Multiplication H(5) * H^-1(5)")
#print(hilbert(5).dot(invhilbert(5)))
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))
print("Matrix Multiplication H(",n,") * H^-1(",n,") for rounded matrix")
print(h.dot(inv(h).round(m)))
#p2 = invhilbert(n)
#print("Percentage-Error For n = ",n," m = ",m)
#print(np.divide(p2,p1)*100)
HilbertApprox(3,2)
HilbertApprox(4,2)
HilbertApprox(5,2)
#HilbertApprox(3,4)
#HilbertApprox(4,4)
#HilbertApprox(5,4)
#HilbertApprox(3,5)
#HilbertApprox(4,5)
#HilbertApprox(5,5)
#HilbertApprox(3,6)
#HilbertApprox(4,6)
#HilbertApprox(5,6)
#HilbertApprox(3,7)
#HilbertApprox(4,7)
#HilbertApprox(5,7)
#HilbertApprox(3,8)
#HilbertApprox(4,8)
#HilbertApprox(5,8)
#HilbertApprox(3,9)
#HilbertApprox(4,9)
#HilbertApprox(5,9)
#HilbertApprox(3,10)
#HilbertApprox(4,10)
#HilbertApprox(5,10)
#print(type(hilbert(2)))
#a = [1,3.004,5.2222]
#[round(i,2) for i in a]
#print(a)