thouis / numpy-trac-migration

numpy Trac to github issues migration
2 stars 3 forks source link

chebval: subtract half of first coefficient? (Trac #2208) #5997

Closed numpy-gitbot closed 11 years ago

numpy-gitbot commented 11 years ago

Original ticket http://projects.scipy.org/numpy/ticket/2208 on 2012-08-28 by trac user smeared ink, assigned to atmention:charris.

I am very new to evaluating Chebyshev polynomials, but shouldn't chebval subtract off 0.5*(first coefficient), as in Numerical Recipes, or here?: http://mathworld.wolfram.com/ChebyshevApproximationFormula.html (which cites Numerical Recipes, actually).

I was finding unexpected differences in how numpy evaluated Chebyshev polynomials from some code I was trying to replicate, and I traced it back to this little thing.

numpy-gitbot commented 11 years ago

atmention:charris wrote on 2012-09-01

No. The reference you give determines the Chebyshev coefficients for fitting a function using the Chebyshev points of the first kind over which the Chebyshev polynomials are orthogonal, but not normalized. The factor of N/2 shown at the link accounts for the lack of normalization except for the T_0 term, which needs an extra factor of .5. Because the chebval function evaluates series, you need to correct the c_0 coefficient determined the NR way before calling chebval. Alternatively, you can fix the normalization factor for the T_0 term up front if you are using a matrix multiply to fit a large number of functions.

Perhaps I should add a function approximation method to the classes. Hmm...