/
6_23chebypoly.py
39 lines (33 loc) · 972 Bytes
/
6_23chebypoly.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
34
35
36
37
38
39
from p6_22legendre import ansatz, evalp
from fivepoint import fivepoint
from scipy import *
from matplotlib import *
from pylab import *
def normalisecheby(P):
for j in range(len(P)):
P/=fivepoint(lambda x:evalp(P,x)**2/((1-x*x)**0.5),-1,1,10)**0.5
return P
def gramsmidtcheby(n):
P=ansatz(n)
for m in range(len(P)):
for j in range(len(P[m])-1):
for i in range(len(P[j])):
tmp = fivepoint(lambda x:evalp(P[m],x)*evalp(P[j],x)/((1-x*x)**0.5),-1,1,10)
P[m][i]-=tmp*P[j][i]
P[m]=normalisecheby(P[m])
return P
def chebychev(n):
P=gramsmidtcheby(n)
P[0]=pi**0.5*P[0]
for i in range(1,len(P)):
P[i]=(pi/2)**0.5*P[i]
return P
if __name__ == '__main__':
Coeffs=chebychev(5)
x=arange(-1,1,0.01)
for i in range(len(Coeffs)):
y=[]
for j in range(len(x)):
y.append(evalp(Coeffs[i],x[j]))
plot(x,y)
show()