MCPcopy Create free account
hub / github.com/numpy/numpy / lag2poly

Function lag2poly

numpy/polynomial/laguerre.py:141–193  ·  view source on GitHub ↗

Convert a Laguerre series to a polynomial. Convert an array representing the coefficients of a Laguerre series, ordered from lowest degree to highest, to an array of the coefficients of the equivalent polynomial (relative to the "standard" basis) ordered from lowest to highest

(c)

Source from the content-addressed store, hash-verified

139
140
141def lag2poly(c):
142 """
143 Convert a Laguerre series to a polynomial.
144
145 Convert an array representing the coefficients of a Laguerre series,
146 ordered from lowest degree to highest, to an array of the coefficients
147 of the equivalent polynomial (relative to the "standard" basis) ordered
148 from lowest to highest degree.
149
150 Parameters
151 ----------
152 c : array_like
153 1-D array containing the Laguerre series coefficients, ordered
154 from lowest order term to highest.
155
156 Returns
157 -------
158 pol : ndarray
159 1-D array containing the coefficients of the equivalent polynomial
160 (relative to the "standard" basis) ordered from lowest order term
161 to highest.
162
163 See Also
164 --------
165 poly2lag
166
167 Notes
168 -----
169 The easy way to do conversions between polynomial basis sets
170 is to use the convert method of a class instance.
171
172 Examples
173 --------
174 >>> from numpy.polynomial.laguerre import lag2poly
175 >>> lag2poly([ 23., -63., 58., -18.])
176 array([0., 1., 2., 3.])
177
178 """
179 from .polynomial import polyadd, polysub, polymulx
180
181 [c] = pu.as_series([c])
182 n = len(c)
183 if n == 1:
184 return c
185 else:
186 c0 = c[-2]
187 c1 = c[-1]
188 # i is the current degree of c1
189 for i in range(n - 1, 1, -1):
190 tmp = c0
191 c0 = polysub(c[i - 2], (c1*(i - 1))/i)
192 c1 = polyadd(tmp, polysub((2*i - 1)*c1, polymulx(c1))/i)
193 return polyadd(c0, polysub(c1, polymulx(c1)))
194
195#
196# These are constant arrays are of integer type so as to be compatible

Callers

nothing calls this directly

Calls 3

polymulxFunction · 0.85
polysubFunction · 0.70
polyaddFunction · 0.70

Tested by

no test coverage detected