Path: | rdoc/interp.rdoc |
Last Update: | Sun Nov 14 14:53:48 -0800 2010 |
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.
These methods create an interpolation object of type T for n data-points.
The library provides six types, which are specifiled by an identifier of a constant or a string:
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.
Cubic spline with periodic boundary conditions
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.
sp = Interp.alloc("cspline", 10)
This method initializes the interpolation object interp for the data (xa,ya) where xa and ya are vectors. The interpolation object (GSL::Interp) does not save the data vectors xa, ya and only stores the static state computed from the data. The xa vector is always assumed to be strictly ordered; the behavior for other arrangements is not defined.
This returns the name of the interpolation type used by self.
This returns the minimum number of points required by the interpolation type of self. For example, Akima spline interpolation requires a minimum of 5 points.
This returns the index i of the vector xa such that xa[i] <= x < x[i+1]. The index is searched for in the range [index_lo,index_hi].
In C level, the library requires a gsl_interp_accel object, but it is hidden in Ruby/GSL. It is automatically allocated when a GSL::Interp object is created, stored in it, and destroyed when the Interp object is cleaned by the Ruby GC. This method is used to access to the Interp::Accel object stored in self.
This method performs a lookup action on the data array xa. This is how lookups are performed during evaluation of an interpolation. The function returns an index i such that xa[i] <= x < xa[i+1].
These methods return the interpolated value for a given point x, using the interpolation object self, data vectors xa and ya. The data x can be a Numeric, Vector, Matrix or an NArray.
These methods return the derivative of an interpolated function for a given point x, using the interpolation object self, data vectors xa and ya.
These methods return the second derivative of an interpolated function for a given point x, using the interpolation object self, data vectors xa and ya.
These methods return the numerical integral result of an interpolated function over the range [a, b], using the interpolation object self, data vectors xa and ya.
This creates a GSL::Spline object of type T for n data-points. The type T is the same as GSL::Interp class.
These two are equivalent.
sp = GSL::Spline.alloc(T, n) sp.init(x, y) # x and y are vectors of length n
sp = GSL::Spline.alloc(T, x, y)
If T is not given, "cspline" is used.
This initializes a GSL::Spline object self for the data (xa, ya) where xa and ya are Ruby arrays of equal sizes or GSL::Vector.
This returns the name of the spline type used by self.
This returns the interpolated value for a given point x. The data x can be a Numeric, Vector, Matrix or an NArray.
NOTE: In a GSL-C program, a gsl_interp_accel object is required to use the function gsl_spline_eval. In Ruby/GSL, the gsl_interp_accel is hidden, it is automatically allocated when a GSL::Spline object is created, and also destroyed when the Spline object is cleaned by the Ruby GC. The accel object can be accessed via the method GSL::Spline#accel.
This returns the derivative of an interpolated function for a given point x, usingthe data arrays xa and ya set by init.
This returns the second derivative at x.
Returns the numerical integral over the range [a, b].
This method performs a lookup action on the data array xa. This is how lookups are performed during evaluation of an interpolation. The function returns an index i such that xa[i] <= x < xa[i+1].
See also the GSL manual and the examples in examples/