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

Function chebdiv

numpy/polynomial/chebyshev.py:750–814  ·  view source on GitHub ↗

Divide one Chebyshev series by another. Returns the quotient-with-remainder of two Chebyshev series `c1` / `c2`. The arguments are sequences of coefficients from lowest order "term" to highest, e.g., [1,2,3] represents the series ``T_0 + 2*T_1 + 3*T_2``. Parameters --

(c1, c2)

Source from the content-addressed store, hash-verified

748
749
750def chebdiv(c1, c2):
751 """
752 Divide one Chebyshev series by another.
753
754 Returns the quotient-with-remainder of two Chebyshev series
755 `c1` / `c2`. The arguments are sequences of coefficients from lowest
756 order "term" to highest, e.g., [1,2,3] represents the series
757 ``T_0 + 2*T_1 + 3*T_2``.
758
759 Parameters
760 ----------
761 c1, c2 : array_like
762 1-D arrays of Chebyshev series coefficients ordered from low to
763 high.
764
765 Returns
766 -------
767 [quo, rem] : ndarrays
768 Of Chebyshev series coefficients representing the quotient and
769 remainder.
770
771 See Also
772 --------
773 chebadd, chebsub, chebmulx, chebmul, chebpow
774
775 Notes
776 -----
777 In general, the (polynomial) division of one C-series by another
778 results in quotient and remainder terms that are not in the Chebyshev
779 polynomial basis set. Thus, to express these results as C-series, it
780 is typically necessary to "reproject" the results onto said basis
781 set, which typically produces "unintuitive" (but correct) results;
782 see Examples section below.
783
784 Examples
785 --------
786 >>> from numpy.polynomial import chebyshev as C
787 >>> c1 = (1,2,3)
788 >>> c2 = (3,2,1)
789 >>> C.chebdiv(c1,c2) # quotient "intuitive," remainder not
790 (array([3.]), array([-8., -4.]))
791 >>> c2 = (0,1,2,3)
792 >>> C.chebdiv(c2,c1) # neither "intuitive"
793 (array([0., 2.]), array([-2., -4.]))
794
795 """
796 # c1, c2 are trimmed copies
797 [c1, c2] = pu.as_series([c1, c2])
798 if c2[-1] == 0:
799 raise ZeroDivisionError()
800
801 # note: this is more efficient than `pu._div(chebmul, c1, c2)`
802 lc1 = len(c1)
803 lc2 = len(c2)
804 if lc1 < lc2:
805 return c1[:1]*0, c1
806 elif lc2 == 1:
807 return c1/c2[-1], c1[:1]*0

Callers

nothing calls this directly

Calls 3

_cseries_to_zseriesFunction · 0.85
_zseries_divFunction · 0.85
_zseries_to_cseriesFunction · 0.85

Tested by

no test coverage detected