Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Chebyshev polynomial implementation in scipy and numpy

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!

like image 522
Elina Gilbert Avatar asked Dec 01 '25 15:12

Elina Gilbert


1 Answers

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.])
like image 50
Eric Avatar answered Dec 04 '25 04:12

Eric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!