This chapter describes routines for computing Chebyshev approximations to univariate functions.  A Chebyshev approximation is a truncation of the series f(x) = \sum c_n T_n(x), where the Chebyshev polynomials T_n(x) = \cos(n \arccos x) provide an orthogonal basis of polynomials on the interval [-1,1] with the weight function $1 / \sqrt1-x^2$ 1 / \sqrt{1-x^2}.  The first few Chebyshev polynomials are, T_0(x) = 1, T_1(x) = x, T_2(x) = 2 x^2 - 1. For further information see Abramowitz & Stegun, Chapter 22.

The functions described in this chapter are declared in the header file gsl_chebyshev.h.

Definitions
===========

A Chebyshev series  is stored using the following structure,

     typedef struct
     {
       double * c;   /* coefficients  c[0] .. c[order] */
       int order;    /* order of expansion             */
       double a;     /* lower interval point           */
       double b;     /* upper interval point           */
       ...
     } gsl_cheb_series

The approximation is made over the range [a,b] using ORDER+1 terms, including the coefficient c[0].  The series is computed using the following convention,

     f(x) = (c_0 / 2) + \sum_{n=1} c_n T_n(x)

which is needed when accessing the coefficients directly.

Creation and Calculation of Chebyshev Series
============================================

 -- Function: gsl_cheb_series * gsl_cheb_alloc (const size_t N)
     This function allocates space for a Chebyshev series of order N and returns a pointer to a new gsl_cheb_series struct.

 -- Function: void gsl_cheb_free (gsl_cheb_series * CS)
     This function frees a previously allocated Chebyshev series CS.

 -- Function: int gsl_cheb_init (gsl_cheb_series * CS, const gsl_function * F, const double A, const double B)
     This function computes the Chebyshev approximation CS for the function F over the range (a,b) to the previously specified order.  The computation of the Chebyshev approximation is an O(n^2) process, and requires n function evaluations.

Auxiliary Functions
===================

The following functions provide information about an existing Chebyshev series.

 -- Function: size_t gsl_cheb_order (const gsl_cheb_series * CS)
     This function returns the order of Chebyshev series CS.

 -- Function: size_t gsl_cheb_size (const gsl_cheb_series * CS)
 -- Function: double * gsl_cheb_coeffs (const gsl_cheb_series * CS)
     These functions return the size of the Chebyshev coefficient array c[] and a pointer to its location in memory for the Chebyshev series CS.

Chebyshev Series Evaluation
===========================

 -- Function: double gsl_cheb_eval (const gsl_cheb_series * CS, double X)
     This function evaluates the Chebyshev series CS at a given point X.

 -- Function: int gsl_cheb_eval_err (const gsl_cheb_series * CS, const double X, double * RESULT, double * ABSERR)
     This function computes the Chebyshev series CS at a given point X, estimating both the series RESULT and its absolute error ABSERR.  The error estimate is made from the first neglected term in the series.

 -- Function: double gsl_cheb_eval_n (const gsl_cheb_series * CS, size_t ORDER, double X)
     This function evaluates the Chebyshev series CS at a given point X, to (at most) the given order ORDER.

 -- Function: int gsl_cheb_eval_n_err (const gsl_cheb_series * CS, const size_t ORDER, const double X, double * RESULT, double * ABSERR)
     This function evaluates a Chebyshev series CS at a given point X, estimating both the series RESULT and its absolute error ABSERR, to (at most) the given order ORDER.  The error estimate is made from the first neglected term in the series.

Derivatives and Integrals
=========================

The following functions allow a Chebyshev series to be differentiated or integrated, producing a new Chebyshev series.  Note that the error estimate produced by evaluating the derivative series will be underestimated due to the contribution of higher order terms being neglected.

 -- Function: int gsl_cheb_calc_deriv (gsl_cheb_series * DERIV, const gsl_cheb_series * CS)
     This function computes the derivative of the series CS, storing the derivative coefficients in the previously allocated DERIV. The two series CS and DERIV must have been allocated with the same order.

 -- Function: int gsl_cheb_calc_integ (gsl_cheb_series * INTEG, const gsl_cheb_series * CS)
     This function computes the integral of the series CS, storing the integral coefficients in the previously allocated INTEG.  The two series CS and INTEG must have been allocated with the same order.  The lower limit of the integration is taken to be the left hand end of the range A.

Examples
========

The following example program computes Chebyshev approximations to a step function.  This is an extremely difficult approximation to make, due to the discontinuity, and was chosen as an example where approximation error is visible.  For smooth functions the Chebyshev approximation converges extremely rapidly and errors would not be visible.

          [file cheb.c not included]

The output from the program gives the original function, 10-th order approximation and 40-th order approximation, all sampled at intervals of 0.001 in x.

References and Further Reading
==============================

The following paper describes the use of Chebyshev series,

  R. Broucke, ``Ten Subroutines for the Manipulation of Chebyshev Series [C1] (Algorithm 446)''. Communications of the ACM 16(4), 254--256 (1973)