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

Function chebinterpolate

numpy/polynomial/chebyshev.py:1780–1844  ·  view source on GitHub ↗

Interpolate a function at the Chebyshev points of the first kind. Returns the Chebyshev series that interpolates `func` at the Chebyshev points of the first kind in the interval [-1, 1]. The interpolating series tends to a minmax approximation to `func` with increasing `deg` if the

(func, deg, args=())

Source from the content-addressed store, hash-verified

1778
1779
1780def chebinterpolate(func, deg, args=()):
1781 """Interpolate a function at the Chebyshev points of the first kind.
1782
1783 Returns the Chebyshev series that interpolates `func` at the Chebyshev
1784 points of the first kind in the interval [-1, 1]. The interpolating
1785 series tends to a minmax approximation to `func` with increasing `deg`
1786 if the function is continuous in the interval.
1787
1788 .. versionadded:: 1.14.0
1789
1790 Parameters
1791 ----------
1792 func : function
1793 The function to be approximated. It must be a function of a single
1794 variable of the form ``f(x, a, b, c...)``, where ``a, b, c...`` are
1795 extra arguments passed in the `args` parameter.
1796 deg : int
1797 Degree of the interpolating polynomial
1798 args : tuple, optional
1799 Extra arguments to be used in the function call. Default is no extra
1800 arguments.
1801
1802 Returns
1803 -------
1804 coef : ndarray, shape (deg + 1,)
1805 Chebyshev coefficients of the interpolating series ordered from low to
1806 high.
1807
1808 Examples
1809 --------
1810 >>> import numpy.polynomial.chebyshev as C
1811 >>> C.chebfromfunction(lambda x: np.tanh(x) + 0.5, 8)
1812 array([ 5.00000000e-01, 8.11675684e-01, -9.86864911e-17,
1813 -5.42457905e-02, -2.71387850e-16, 4.51658839e-03,
1814 2.46716228e-17, -3.79694221e-04, -3.26899002e-16])
1815
1816 Notes
1817 -----
1818
1819 The Chebyshev polynomials used in the interpolation are orthogonal when
1820 sampled at the Chebyshev points of the first kind. If it is desired to
1821 constrain some of the coefficients they can simply be set to the desired
1822 value after the interpolation, no new interpolation or fit is needed. This
1823 is especially useful if it is known apriori that some of coefficients are
1824 zero. For instance, if the function is even then the coefficients of the
1825 terms of odd degree in the result can be set to zero.
1826
1827 """
1828 deg = np.asarray(deg)
1829
1830 # check arguments.
1831 if deg.ndim > 0 or deg.dtype.kind not in 'iu' or deg.size == 0:
1832 raise TypeError("deg must be an int")
1833 if deg < 0:
1834 raise ValueError("expected deg >= 0")
1835
1836 order = deg + 1
1837 xcheb = chebpts1(order)

Callers 1

interpolateMethod · 0.85

Calls 4

chebpts1Function · 0.85
chebvanderFunction · 0.85
dotMethod · 0.80
funcFunction · 0.50

Tested by

no test coverage detected