1 """Jacobi polynomials and Vandermonde matrices."""
2
3 from __future__ import division
4
5 __copyright__ = "Copyright (C) 2007 Andreas Kloeckner"
6
7 __license__ = """
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see U{http://www.gnu.org/licenses/}.
20 """
21
22
23
24
25
26 import numpy
27 import hedge._internal
28 import numpy.linalg as la
29
30
31
32
33 JacobiFunction = hedge._internal.JacobiPolynomial
34 DiffJacobiFunction = hedge._internal.DiffJacobiPolynomial
35
36
37
38
41 JacobiFunction.__init__(self, 0, 0, N)
42
45 DiffJacobiFunction.__init__(self, 0, 0, N)
46
47
48
49
51 """Return a Vandermonde matrix.
52
53 The Vandermonde Matrix is given by M{V_{i,j} := f_j(x_i)}
54 where C{functions} is the list of M{f_j} and points is
55 the list of M{x_i}.
56 """
57 v = numpy.zeros((len(points), len(functions)))
58 for i, x in enumerate(points):
59 for j, f in enumerate(functions):
60 v[i,j] = f(x)
61 return v
62
63
64
65
67 """Return multiple Vandermonde matrices.
68
69 The Vandermonde Matrix is given by M{V_{i,j} := f_j(x_i)}
70 where C{functions} is the list of M{f_j} and points is
71 the list of M{x_i}.
72
73 The functions M{f_j} are multi-valued (i.e. return iterables), and one
74 matrix is returned for each return value.
75 """
76 count = len(functions[0](points[0]))
77 result = [numpy.zeros((len(points), len(functions))) for n in range(count)]
78
79 for i, x in enumerate(points):
80 for j, f in enumerate(functions):
81 for n, f_n in enumerate(f(x)):
82 result[n][i,j] = f_n
83 return result
84
85
86
87
91
92
93
94
96 class Monomial:
97 def __init__(self, expt):
98 self.expt = expt
99 def __call__(self, x):
100 return x**self.expt
101
102 return generic_vandermonde(levels,
103 [Monomial(i) for i in range(len(levels))])
104
105
106
107
109 point_eval_vec = numpy.array([ tap**n for n in range(len(levels))])
110 return la.solve(monomial_vdm(levels).T, point_eval_vec)
111