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

Function cheb2poly

numpy/polynomial/chebyshev.py:397–455  ·  view source on GitHub ↗

Convert a Chebyshev series to a polynomial. Convert an array representing the coefficients of a Chebyshev 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 highes

(c)

Source from the content-addressed store, hash-verified

395
396
397def cheb2poly(c):
398 """
399 Convert a Chebyshev series to a polynomial.
400
401 Convert an array representing the coefficients of a Chebyshev series,
402 ordered from lowest degree to highest, to an array of the coefficients
403 of the equivalent polynomial (relative to the "standard" basis) ordered
404 from lowest to highest degree.
405
406 Parameters
407 ----------
408 c : array_like
409 1-D array containing the Chebyshev series coefficients, ordered
410 from lowest order term to highest.
411
412 Returns
413 -------
414 pol : ndarray
415 1-D array containing the coefficients of the equivalent polynomial
416 (relative to the "standard" basis) ordered from lowest order term
417 to highest.
418
419 See Also
420 --------
421 poly2cheb
422
423 Notes
424 -----
425 The easy way to do conversions between polynomial basis sets
426 is to use the convert method of a class instance.
427
428 Examples
429 --------
430 >>> from numpy import polynomial as P
431 >>> c = P.Chebyshev(range(4))
432 >>> c
433 Chebyshev([0., 1., 2., 3.], domain=[-1, 1], window=[-1, 1])
434 >>> p = c.convert(kind=P.Polynomial)
435 >>> p
436 Polynomial([-2., -8., 4., 12.], domain=[-1., 1.], window=[-1., 1.])
437 >>> P.chebyshev.cheb2poly(range(4))
438 array([-2., -8., 4., 12.])
439
440 """
441 from .polynomial import polyadd, polysub, polymulx
442
443 [c] = pu.as_series([c])
444 n = len(c)
445 if n < 3:
446 return c
447 else:
448 c0 = c[-2]
449 c1 = c[-1]
450 # i is the current degree of c1
451 for i in range(n - 1, 1, -1):
452 tmp = c0
453 c0 = polysub(c[i - 2], c1)
454 c1 = polyadd(tmp, polymulx(c1)*2)

Callers

nothing calls this directly

Calls 3

polymulxFunction · 0.85
polysubFunction · 0.70
polyaddFunction · 0.70

Tested by

no test coverage detected