Difference between implementation of Chebyshev polynomial in scipy and numpy

Can someone tell me the difference between Chebyshev in numpy-

numpy.polynomial.Chebyshev.basis(deg) 

      

and Chebyshev's meager interpretation

scipy.special.chebyt(deg)

      

This would be very helpful. Thanks in advance!

+3


source to share


1 answer


Polynomial functions scipy.special

use np.poly1d

, which is deprecated and error prone - in particular, it stores the index x0

inpoly.coeffs[-1]

numpy.polynomial.Chebyshev

not only store the coefficients in a more reasonable order, but also store them in terms of their basis, which improves accuracy. You can convert using the method cast

:



>>> from numpy.polynomial import Chebyshev, Polynomial

# note loss of precision
>>> sc_che = scipy.special.chebyt(4); sc_che
poly1d([  8.000000e+00,   0.000000e+00,  -8.000000e+00, 8.881784e-16,   1.000000e+00])

# using the numpy functions - note that the result is just in terms of basis 4
>>> np_che = Chebyshev.basis(4); np_che
Chebyshev([ 0.,  0.,  0.,  0.,  1.], [-1.,  1.], [-1.,  1.])

# converting to a standard polynomial - note that these store the
# coefficient of x^i in .coeffs[i] - so are reversed when compared to above
>>> Polynomial.cast(np_che)
Polynomial([ 1.,  0., -8.,  0.,  8.], [-1.,  1.], [-1.,  1.])

      

+4


source







All Articles