Can anyone please tell me the difference between Chebyshev in numpy-
numpy.polynomial.Chebyshev.basis(deg)
and scipy interpretation of Chebyshev-
scipy.special.chebyt(deg)
It would be of great help. Thanks in advance!
The scipy.special polynomial functions make use of np.poly1d, which is outdated and error prone - in particular, it stores the index of x0 in poly.coeffs[-1]
numpy.polynomial.Chebyshev store coefficients not only in a more sensible order, but keeps them in terms of their basis, which improves precision. You can convert using the cast method:
>>> 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.])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With