| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This chapter describes functions for performing interpolation. The library provides a variety of interpolation methods, including Cubic splines and Akima splines. The interpolation types are interchangeable, allowing different methods to be used without recompiling. Interpolations can be defined for both normal and periodic boundary conditions. Additional functions are available for computing derivatives and integrals of interpolating functions.
The functions described in this section are declared in the header files ‘gsl_interp.h’ and ‘gsl_spline.h’.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Given a set of data points
the
routines described in this section compute a continuous interpolating
function
such that
. The interpolation
is piecewise smooth, and its behavior at the end-points is determined by
the type of interpolation used.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The interpolation function for a given dataset is stored in a
gsl_interp object. These are created by the following functions.
This function returns a pointer to a newly allocated interpolation object of type T for size data-points.
This function initializes the interpolation object interp for the
data (xa,ya) where xa and ya are arrays of size
size. The interpolation object (gsl_interp) does not save
the data arrays xa and ya and only stores the static state
computed from the data. The xa data array is always assumed to be
strictly ordered; the behavior for other arrangements is not defined.
This function frees the interpolation object interp.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The interpolation library provides five interpolation types:
Linear interpolation. This interpolation method does not require any additional memory.
Polynomial interpolation. This method should only be used for interpolating small numbers of points because polynomial interpolation introduces large oscillations, even for well-behaved datasets. The number of terms in the interpolating polynomial is equal to the number of points.
Cubic spline with natural boundary conditions. The resulting curve is piecewise cubic on each interval, with matching first and second derivatives at the supplied data-points. The second derivative is chosen to be zero at the first point and last point.
Cubic spline with periodic boundary conditions. The resulting curve is piecewise cubic on each interval, with matching first and second derivatives at the supplied data-points. The derivatives at the first and last points are also matched. Note that the last point in the data must have the same y-value as the first point, otherwise the resulting periodic interpolation will have a discontinuity at the boundary.
Non-rounded Akima spline with natural boundary conditions. This method uses the non-rounded corner algorithm of Wodicka.
Non-rounded Akima spline with periodic boundary conditions. This method uses the non-rounded corner algorithm of Wodicka.
The following related functions are available:
This function returns the name of the interpolation type used by interp. For example,
printf ("interp uses '%s' interpolation.\n",
gsl_interp_name (interp));
|
would print something like,
interp uses 'cspline' interpolation. |
This function returns the minimum number of points required by the interpolation type of interp. For example, Akima spline interpolation requires a minimum of 5 points.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The state of searches can be stored in a gsl_interp_accel object,
which is a kind of iterator for interpolation lookups. It caches the
previous value of an index lookup. When the subsequent interpolation
point falls in the same interval its index value can be returned
immediately.
This function returns the index
of the array x_array such
that x_array[i] <= x < x_array[i+1]. The index is searched for
in the range [index_lo,index_hi].
This function returns a pointer to an accelerator object, which is a kind of iterator for interpolation lookups. It tracks the state of lookups, thus allowing for application of various acceleration strategies.
This function performs a lookup action on the data array x_array
of size size, using the given accelerator a. This is how
lookups are performed during evaluation of an interpolation. The
function returns an index
such that x_array[i] <= x <
x_array[i+1].
This function frees the accelerator object acc.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These functions return the interpolated value of y for a given point x, using the interpolation object interp, data arrays xa and ya and the accelerator acc.
These functions return the derivative d of an interpolated function for a given point x, using the interpolation object interp, data arrays xa and ya and the accelerator acc.
These functions return the second derivative d2 of an interpolated function for a given point x, using the interpolation object interp, data arrays xa and ya and the accelerator acc.
These functions return the numerical integral result of an interpolated function over the range [a, b], using the interpolation object interp, data arrays xa and ya and the accelerator acc.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The functions described in the previous sections required the user to
supply pointers to the
and
arrays on each call. The
following functions are equivalent to the corresponding
gsl_interp functions but maintain a copy of this data in the
gsl_spline object. This removes the need to pass both xa
and ya as arguments on each evaluation. These functions are
defined in the header file ‘gsl_spline.h’.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following program demonstrates the use of the interpolation and
spline functions. It computes a cubic spline interpolation of the
10-point dataset
where
and
for
.
|
The output is designed to be used with the GNU plotutils
graph program,
$ ./a.out > interp.dat $ graph -T ps < interp.dat > interp.ps |
The result shows a smooth interpolation of the original points. The
interpolation method can changed simply by varying the first argument of
gsl_spline_alloc.
The next program demonstrates a periodic cubic spline with 4 data points. Note that the first and last points must be supplied with the same y-value for a periodic spline.
|
The output can be plotted with GNU graph.
$ ./a.out > interp.dat $ graph -T ps < interp.dat > interp.ps |
The result shows a periodic interpolation of the original points. The slope of the fitted curve is the same at the beginning and end of the data, and the second derivative is also.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Descriptions of the interpolation algorithms and further references can be found in the following books:
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated by Autobuild on September, 26 2007 using texi2html 1.78.