1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import scipy
18 import numpy
19
21 """
22 A function to compute the positions (x,y) of the nodes of the
23 2-dimensional Chebyshev polynomials of degree (N1,N2).
24 """
25
26 x_cheby = numpy.array([numpy.cos(numpy.pi*(2*idx+1)/N1/2) for idx in range(N1)])
27 y_cheby = numpy.array([numpy.cos(numpy.pi*(2*idx+1)/N2/2) for idx in range(N2)])
28 return scipy.meshgrid(x_cheby, x_cheby)
29
30
32 """
33 A wrapper for scipy's factorial.
34 """
35
36 return scipy.factorial(x,exact=1)
37
39 """
40 A function that returns the (n,m)th 2-dimensional Chebyshev
41 polynomials of degree (N,M) at the locations given in x and y.
42 """
43
44 ux = numpy.zeros(scipy.shape(x))
45 uy = numpy.zeros(scipy.shape(y))
46 for thisn1 in range(n1/2+1):
47 ux += (x**2.-1.)**(thisn1) * x**(n1-2*thisn1) * factorial(n1)/factorial(2*thisn1)/factorial(n1-2*thisn1)
48 for thisn2 in range(n2/2+1):
49 uy += (y**2.-1.)**(thisn2) * y**(n2-2*thisn2) * factorial(n2)/factorial(2*thisn2)/factorial(n2-2*thisn2)
50
51 w = 1.
52 if n1:
53 w *= N1/2.
54 else:
55 w *= N1
56 if n2:
57 w *= N2/2.
58 else:
59 w *= N2
60 return ux*uy/w**.5
61
63 """
64 A function that creates all of the 2-dimensional Chebyshev polynomials
65 of degree (N1,N2) evalulated at positions given by (x,y).
66 """
67
68 Us = []
69 for idx in range(N1):
70 Us.append([])
71 for jdx in range(N2):
72 Us[idx].append(T_cheby_2D(x, y, idx, N1, jdx, N2))
73 Us = numpy.array(Us)
74 return Us
75
77 """
78 A function that takes function measurements at the interpolation
79 locations and computes the interpolation coefficients associated with
80 the 2-dimensional Chebyshev polynomials of degree (N1,N2) (Us).
81 """
82
83 coeffs = []
84 for idx in range(N1):
85 coeffs.append([])
86 for jdx in range(N2):
87 coeffs[idx].append(sum((func_measurements*Us[idx][jdx]).flatten()))
88 return coeffs
89
91 """
92 A function that takes interpolation coefficients associated with
93 the 2-dimensional Chebyshev polynomials of degree (N1,N2) and
94 recontructs the interpolated function at locations where the
95 2-dimensional Chebyshev polynomials of degree (N1,N2) (Vs) have been sampled.
96 """
97
98 func_interpolated = numpy.zeros(numpy.shape(Vs[0,0]))
99 for idx in range(N1):
100 for jdx in range(N2):
101 func_interpolated += coeffs[idx][jdx]*Vs[idx,jdx]
102 return func_interpolated
103