1 @cindex Chebyshev series
2 @cindex fitting, using Chebyshev polynomials
3 @cindex interpolation, using Chebyshev polynomials
5 This chapter describes routines for computing Chebyshev approximations
6 to univariate functions. A Chebyshev approximation is a truncation of
7 the series @math{f(x) = \sum c_n T_n(x)}, where the Chebyshev
8 polynomials @math{T_n(x) = \cos(n \arccos x)} provide an orthogonal
9 basis of polynomials on the interval @math{[-1,1]} with the weight
10 function @c{$1 / \sqrt{1-x^2}$}
11 @math{1 / \sqrt@{1-x^2@}}. The first few Chebyshev polynomials are,
12 @math{T_0(x) = 1}, @math{T_1(x) = x}, @math{T_2(x) = 2 x^2 - 1}.
13 For further information see Abramowitz & Stegun, Chapter 22.
15 The functions described in this chapter are declared in the header file
16 @file{gsl_chebyshev.h}.
19 * Chebyshev Definitions::
20 * Creation and Calculation of Chebyshev Series::
21 * Chebyshev Series Evaluation::
22 * Derivatives and Integrals::
23 * Chebyshev Approximation examples::
24 * Chebyshev Approximation References and Further Reading::
27 @node Chebyshev Definitions
30 A Chebyshev series is stored using the following structure,
35 double * c; /* coefficients c[0] .. c[order] */
36 int order; /* order of expansion */
37 double a; /* lower interval point */
38 double b; /* upper interval point */
44 The approximation is made over the range @math{[a,b]} using
45 @var{order}+1 terms, including the coefficient @math{c[0]}. The series
46 is computed using the following convention,
50 f(x) = {c_0 \over 2} + \sum_{n=1} c_n T_n(x)
57 f(x) = (c_0 / 2) + \sum_@{n=1@} c_n T_n(x)
62 which is needed when accessing the coefficients directly.
64 @node Creation and Calculation of Chebyshev Series
65 @section Creation and Calculation of Chebyshev Series
67 @deftypefun {gsl_cheb_series *} gsl_cheb_alloc (const size_t @var{n})
68 This function allocates space for a Chebyshev series of order @var{n}
69 and returns a pointer to a new @code{gsl_cheb_series} struct.
72 @deftypefun void gsl_cheb_free (gsl_cheb_series * @var{cs})
73 This function frees a previously allocated Chebyshev series @var{cs}.
76 @deftypefun int gsl_cheb_init (gsl_cheb_series * @var{cs}, const gsl_function * @var{f}, const double @var{a}, const double @var{b})
77 This function computes the Chebyshev approximation @var{cs} for the
78 function @var{f} over the range @math{(a,b)} to the previously specified
79 order. The computation of the Chebyshev approximation is an
80 @math{O(n^2)} process, and requires @math{n} function evaluations.
83 @node Chebyshev Series Evaluation
84 @section Chebyshev Series Evaluation
86 @deftypefun double gsl_cheb_eval (const gsl_cheb_series * @var{cs}, double @var{x})
87 This function evaluates the Chebyshev series @var{cs} at a given point @var{x}.
90 @deftypefun int gsl_cheb_eval_err (const gsl_cheb_series * @var{cs}, const double @var{x}, double * @var{result}, double * @var{abserr})
91 This function computes the Chebyshev series @var{cs} at a given point
92 @var{x}, estimating both the series @var{result} and its absolute error
93 @var{abserr}. The error estimate is made from the first neglected term
97 @deftypefun double gsl_cheb_eval_n (const gsl_cheb_series * @var{cs}, size_t @var{order}, double @var{x})
98 This function evaluates the Chebyshev series @var{cs} at a given point
99 @var{n}, to (at most) the given order @var{order}.
102 @deftypefun int gsl_cheb_eval_n_err (const gsl_cheb_series * @var{cs}, const size_t @var{order}, const double @var{x}, double * @var{result}, double * @var{abserr})
103 This function evaluates a Chebyshev series @var{cs} at a given point
104 @var{x}, estimating both the series @var{result} and its absolute error
105 @var{abserr}, to (at most) the given order @var{order}. The error
106 estimate is made from the first neglected term in the series.
109 @comment @deftypefun double gsl_cheb_eval_mode (const gsl_cheb_series * @var{cs}, double @var{x}, gsl_mode_t @var{mode})
110 @comment @end deftypefun
112 @comment @deftypefun int gsl_cheb_eval_mode_err (const gsl_cheb_series * @var{cs}, const double @var{x}, gsl_mode_t @var{mode}, double * @var{result}, double * @var{abserr})
113 @comment Evaluate a Chebyshev series at a given point, using the default
114 @comment order for double precision mode(s) and the single precision
115 @comment order for other modes.
116 @comment @end deftypefun
119 @node Derivatives and Integrals
120 @section Derivatives and Integrals
122 The following functions allow a Chebyshev series to be differentiated or
123 integrated, producing a new Chebyshev series. Note that the error
124 estimate produced by evaluating the derivative series will be
125 underestimated due to the contribution of higher order terms being
128 @deftypefun int gsl_cheb_calc_deriv (gsl_cheb_series * @var{deriv}, const gsl_cheb_series * @var{cs})
129 This function computes the derivative of the series @var{cs}, storing
130 the derivative coefficients in the previously allocated @var{deriv}.
131 The two series @var{cs} and @var{deriv} must have been allocated with
135 @deftypefun int gsl_cheb_calc_integ (gsl_cheb_series * @var{integ}, const gsl_cheb_series * @var{cs})
136 This function computes the integral of the series @var{cs}, storing the
137 integral coefficients in the previously allocated @var{integ}. The two
138 series @var{cs} and @var{integ} must have been allocated with the same
139 order. The lower limit of the integration is taken to be the left hand
140 end of the range @var{a}.
143 @node Chebyshev Approximation examples
146 The following example program computes Chebyshev approximations to a
147 step function. This is an extremely difficult approximation to make,
148 due to the discontinuity, and was chosen as an example where
149 approximation error is visible. For smooth functions the Chebyshev
150 approximation converges extremely rapidly and errors would not be
154 @verbatiminclude examples/cheb.c
158 The output from the program gives the original function, 10-th order
159 approximation and 40-th order approximation, all sampled at intervals of
164 @center @image{cheb,3.4in}
167 @node Chebyshev Approximation References and Further Reading
168 @section References and Further Reading
170 The following paper describes the use of Chebyshev series,
174 R. Broucke, ``Ten Subroutines for the Manipulation of Chebyshev Series
175 [C1] (Algorithm 446)''. @cite{Communications of the ACM} 16(4), 254--256