-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptest.py
33 lines (28 loc) · 841 Bytes
/
ptest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import peval
import pfit
import random
import numpy as np
if __name__== "__main__":
#test Horner's method implementation vs Pythons
maxabserr = 0
maxpolyval=0
for i in range(10):
d = random.randint(2,20)
xs = [0]*(d+1)
for j in range(d+1):
xs[j] = random.random() * 5 - 10
#print(xs)
for j in range(-10,10):
t1 = peval.pEval(j * 1.0,xs)
ys = np.flipud(xs)
t2 = np.polyval(ys,j * 1.0)
maxmabserr = max(maxabserr, abs(t1-t2))
maxpolyval = max(maxpolyval,t1)
print (maxabserr)
print (maxpolyval)
xsubk = (0,2.5,3.14,-3,-2)
fsubk = (-2,5.5,10,-2,-5)
#asubk = pfit.pFit(xsubk,fsubk)
#print (asubk)
#for i in range(len(xsubk)):
# print (peval.pEval(xsubk[i],asubk), fsubk[i])