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

Function legfromroots

numpy/polynomial/legendre.py:267–319  ·  view source on GitHub ↗

Generate a Legendre series with given roots. The function returns the coefficients of the polynomial .. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n), in Legendre form, where the `r_n` are the roots specified in `roots`. If a zero has multiplicity n, then it must appe

(roots)

Source from the content-addressed store, hash-verified

265
266
267def legfromroots(roots):
268 """
269 Generate a Legendre series with given roots.
270
271 The function returns the coefficients of the polynomial
272
273 .. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n),
274
275 in Legendre form, where the `r_n` are the roots specified in `roots`.
276 If a zero has multiplicity n, then it must appear in `roots` n times.
277 For instance, if 2 is a root of multiplicity three and 3 is a root of
278 multiplicity 2, then `roots` looks something like [2, 2, 2, 3, 3]. The
279 roots can appear in any order.
280
281 If the returned coefficients are `c`, then
282
283 .. math:: p(x) = c_0 + c_1 * L_1(x) + ... + c_n * L_n(x)
284
285 The coefficient of the last term is not generally 1 for monic
286 polynomials in Legendre form.
287
288 Parameters
289 ----------
290 roots : array_like
291 Sequence containing the roots.
292
293 Returns
294 -------
295 out : ndarray
296 1-D array of coefficients. If all roots are real then `out` is a
297 real array, if some of the roots are complex, then `out` is complex
298 even if all the coefficients in the result are real (see Examples
299 below).
300
301 See Also
302 --------
303 numpy.polynomial.polynomial.polyfromroots
304 numpy.polynomial.chebyshev.chebfromroots
305 numpy.polynomial.laguerre.lagfromroots
306 numpy.polynomial.hermite.hermfromroots
307 numpy.polynomial.hermite_e.hermefromroots
308
309 Examples
310 --------
311 >>> import numpy.polynomial.legendre as L
312 >>> L.legfromroots((-1,0,1)) # x^3 - x relative to the standard basis
313 array([ 0. , -0.4, 0. , 0.4])
314 >>> j = complex(0,1)
315 >>> L.legfromroots((-j,j)) # x^2 + 1 relative to the standard basis
316 array([ 1.33333333+0.j, 0.00000000+0.j, 0.66666667+0.j]) # may vary
317
318 """
319 return pu._fromroots(legline, legmul, roots)
320
321
322def legadd(c1, c2):

Callers

nothing calls this directly

Calls 1

_fromrootsMethod · 0.80

Tested by

no test coverage detected