Ticket #664 (closed enhancement: wontfix)
more accurate representation of polynomials
| Reported by: | pv | Owned by: | somebody |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.1.0 |
| Component: | numpy.lib | Version: | none |
| Keywords: | Cc: | pav@… |
Description
numpy.poly1d represents polynomials by storing the polynomial coefficients. I believe that for high-order polynomials, this is not always the optimal way to represent them.
Consider one of the orthogonal polynomial functions in scipy.special:
>>> import scipy, scipy.special >>> for n in xrange(0,70,10): print n, scipy.special.chebyt(n)(scipy.cos(z)) - scipy.cos(n*z) 0 0.0 10 3.80806497446e-14 20 1.94978477808e-10 30 2.65364360286e-06 40 -0.0237953834481 50 -114.714051465 60 272370.465462
It can be seen that as the order of the polynomial increases, the accuracy of evaluation decreases very rapidly, and for n > 40 the result is basically numerical noise.
The scipy.special.chebyt function generates a poly1d object by passing the roots of the polynomial to poly1d. In poly1d.init, polynomial coefficients are calculated from the roots. For high-order Chebyshev polynomials, the coefficients are large and of varying sign which leads to loss of precision when evaluating the polynomial.
It might be useful if there was a poly1d-compatible object that would retain a more accurate representation of the polynomial. (Using the roots, or a Horner scheme?) This would come useful when more information than the coefficients is initially available.
