How to accurately summate Clenshaw algorithm

Viewed 92

I have following code to summate Chebyshev expansion of a function using Clenshaw algorithm:

long double summate_chebyshev(long double x, long double* c, int count) {
    long double bn, bn_1 = 0, bn_2 = 0;
    for (int i = count - 1; i > 0; i--) {
        bn = c[i] + 2.0*x*bn_1 - bn_2;
        bn_2 = bn_1;
        bn_1 = bn;

    }
    bn = 2.0l*c[0] + 2.0*x*bn_1 - bn_2;
    return (bn - bn_2)/2.0l;
}

I gives me pretty nice precision but Chebyshev polynomial coefficients tend to converge to 0 pretty quickly (c[17] is already 4.34e-20 < LDBL_EPS, so it ignores it). I wish to increase accuracy of summation and add more terms that is quite small but make the difference together. Is there any way to achieve this (improved versions of Clenshaw summation or any other method to evaluate Chebyshev polynomials accurately)?

0 Answers
Related