S-Lang GSL Module Reference: gslinterp: The GSL Interpolation Module

Next Previous Contents

## 4. gslinterp: The GSL Interpolation Module

The `gslinterp` module provides S-Lang interpreter access to GSL's interpolations routines. The interpolation methods include linear, polynomial, and spline interpolation. Both Cubic and Akima splines are supported with normal or periodic boundary conditions. In addition, routines for computing first and second order derivatives, as well as integrals based upon these interpolation methods are included.

The wrapping of these functions differs somewhat from the interface provided by the GSL API in the interest of ease of use. The `gslinterp` modules actual defines two interfaces to the underlying GSL routines.

The higher-level interface is the simplest to use and should suffice for most applications. As an example of its use, suppose one has a set of (x,y) pairs represented by the arrays `xa` and `ya` that one wants to use for interpolation. Then

> `

>         y = interp_cspline (x, xa, ya);

> `

will fit a cubic spline to the points and return the of the spline at the point `x`. If `x` is an array, then the spline will be evaluated at each of the points in the array returning an array of the same shape.

The low-level interface consists of several method-specific initialization functions and functions that carry out the actual interpolation. The above example may be written in terms of this interface as

> `

>         c = interp_cspline_init (xa, ya);
>         y = interp_eval (c, x);

> `

Here `interp_cspline_init` returns an object of type `GSL_Interp_Type` that represents the spline function. It is then passed to the `interp_eval` function to evaluate the spline at `x`.

The advantage of the lower level interface is that it moves the overhead associated with the computation of the interpolating function (the spline in the above example) out of the function that performs the interpolation. This means that code such as

> `

>         c = interp_cspline_init (xa, ya);
>         y0 = interp_eval (c, x0);
>         y1 = interp_eval (c, x1);

> `

will execute in less time than

> `

>         y0 = interp_cspline (x0, xa, ya);
>         y1 = interp_cspline (x1, xa, ya);

> `

## 4.1 Interpolation Routines

### interp_linear

Synopsis

  Linear Interpolation

Usage

  `y = interp_linear (x, Double_Type xa[], Double_Type ya[])`

Description

  Use linear interpolation to determine the value at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

See Also

  `interp_polynomial, interp_cspline, interp_cspline_periodic, interp_akima, interp_akima_periodic`

### interp_polynomial

Synopsis

  Polynomial Interpolation

Usage

  `y = interp_polynomial (x, Double_Type xa[], Double_Type ya[])`

Description

  Use polynomial interpolation to determine the value at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

  The degree of the interpolating polynomial is given by one less than the number of points in the `xa` array. For example, if `length(xa)` is 3, then a quadratic polynomial will be used.

See Also

  `interp_linear, interp_cspline, interp_cspline_periodic, interp_akima, interp_akima_periodic`

### interp_cspline

Synopsis

  Cubic Spline Interpolation

Usage

  `y = interp_cspline (x, Double_Type xa[], Double_Type ya[])`

Description

  Use cubic spline interpolation with natural boundary conditions to determine the value at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

See Also

  `interp_linear, interp_polynomial, interp_cspline_periodic, interp_akima, interp_akima_periodic`

### interp_cspline_periodic

Synopsis

  Cubic spline interpolation with periodic boundary conditions

Usage

  `y = interp_cspline_periodic (x, Double_Type xa[], Double_Type ya[])`

Description

  Use cubic spline interpolation with periodic boundary conditions to determine the value at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

See Also

  `interp_linear, interp_polynomial, interp_cspline, interp_akima, interp_akima_periodic`

### interp_akima

Synopsis

  Akima spline interpolation

Usage

  `y = interp_akima (x, Double_Type xa[], Double_Type ya[])`

Description

  Use an Akima spline with natural boundary conditions to determine the value at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

See Also

  `interp_linear, interp_polynomial, interp_cspline, interp_cspline_periodic, interp_akima_periodic`

### interp_akima_periodic

Synopsis

  Akima spline interpolation with periodic boundary conditions

Usage

  `y = interp_akima_periodic (x, Double_Type xa[], Double_Type ya[])`

Description

  Use an Akima spline with periodic boundary conditions to determine the value at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

See Also

  `interp_linear, interp_polynomial, interp_cspline, interp_cspline_periodic, interp_akima`

## 4.2 First Derivative via Interpolation

### interp_linear_deriv

Synopsis

  Compute derivative using linear interpolation

Usage

  `y = interp_linear_deriv (x, Double_Type xa[], Double_Type ya[])`

Description

  Use linear interpolation to determine the value of the first derivative at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

See Also

  `interp_polynomial_deriv, interp_cspline_deriv, interp_cspline_periodic_deriv, interp_akima_deriv, interp_akima_periodic_deriv`

### interp_polynomial_deriv

Synopsis

  Compute derivative using polynomial interpolation

Usage

  `y = interp_polynomial_deriv (x, Double_Type xa[], Double_Type ya[])`

Description

  Use polynomial interpolation to determine the value of the first derivative at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

  The degree of the interpolating polynomial is given by one less than the number of points in the `xa` array. For example, if `length(xa)` is 3, then a quadratic polynomial will be used.

See Also

  `interp_linear_deriv, interp_cspline_deriv, interp_cspline_periodic_deriv, interp_akima_deriv, interp_akima_periodic_deriv`

### interp_cspline_deriv

Synopsis

  Compute derivative using a cubic spline

Usage

  `y = interp_cspline_deriv (x, Double_Type xa[], Double_Type ya[])`

Description

  Use cubic spline interpolation with natural boundary conditions to determine the value of the first derivative at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

See Also

  `interp_linear_deriv, interp_polynomial_deriv, interp_cspline_periodic_deriv, interp_akima_deriv, interp_akima_periodic_deriv`

### interp_cspline_periodic_deriv

Synopsis

  Compute derivative using a cubic spline

Usage

  `y = interp_cspline_periodic_deriv (x, Double_Type xa[], Double_Type ya[])`

Description

  Use cubic spline interpolation with periodic boundary conditions to determine the value of the first derivative at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

See Also

  `interp_linear_deriv, interp_polynomial_deriv, interp_cspline_deriv, interp_akima_deriv, interp_akima_periodic_deriv`

### interp_akima_deriv

Synopsis

  Compute derivative using an Akima spline

Usage

  `y = interp_akima_deriv (x, Double_Type xa[], Double_Type ya[])`

Description

  Use Akima spline interpolation with natural boundary conditions to determine the value of the first derivative at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

See Also

  `interp_linear_deriv, interp_polynomial_deriv, interp_cspline_deriv, interp_cspline_periodic_deriv, interp_akima_periodic_deriv`

### interp_akima_periodic_deriv

Synopsis

  Compute derivative using an Akima spline

Usage

  `y = interp_cspline_deriv (x, Double_Type xa[], Double_Type ya[])`

Description

  Use Akima spline interpolation with periodic boundary conditions to determine the value of the first derivative at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

See Also

  `interp_linear_deriv, interp_polynomial_deriv, interp_cspline_deriv, interp_cspline_periodic_deriv, interp_akima_deriv`

## 4.3 Second Derivative via Interpolation

### interp_linear_deriv2

Synopsis

  Compute second derivative using linear interpolation

Usage

  `y = interp_linear_deriv2 (x, Double_Type xa[], Double_Type ya[])`

Description

  Use linear interpolation to determine the value of the second derivative at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

See Also

  `interp_polynomial_deriv2, interp_cspline_deriv2, interp_cspline_periodic_deriv2, interp_akima_deriv2, interp_akima_periodic_deriv2`

### interp_polynomial_deriv2

Synopsis

  Compute second derivative using polynomial interpolation

Usage

  `y = interp_polynomial_deriv2 (x, Double_Type xa[], Double_Type ya[])`

Description

  Use polynomial interpolation to determine the value of the second derivative at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

  The degree of the interpolating polynomial is given by one less than the number of points in the `xa` array. For example, if `length(xa)` is 3, then a quadratic polynomial will be used.

See Also

  `interp_linear_deriv2, interp_cspline_deriv2, interp_cspline_periodic_deriv2, interp_akima_deriv2, interp_akima_periodic_deriv2`

### interp_cspline_deriv2

Synopsis

  Compute second derivative using a cubic spline

Usage

  `y = interp_cspline_deriv2 (x, Double_Type xa[], Double_Type ya[])`

Description

  Use cubic spline interpolation with natural boundary conditions to determine the value of the second derivative at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

See Also

  `interp_linear_deriv2, interp_polynomial_deriv2, interp_cspline_periodic_deriv2, interp_akima_deriv2, interp_akima_periodic_deriv2`

### interp_cspline_periodic_deriv2

Synopsis

  Compute second derivative using a cubic spline

Usage

  `y = interp_cspline_periodic_deriv2 (x, Double_Type xa[], Double_Type ya[])`

Description

  Use cubic spline interpolation with periodic boundary conditions to determine the value of the second derivative at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

See Also

  `interp_linear_deriv2, interp_polynomial_deriv2, interp_cspline_deriv2, interp_akima_deriv2, interp_akima_periodic_deriv2`

### interp_akima_deriv2

Synopsis

  Compute second derivative using an Akima spline

Usage

  `y = interp_akima_deriv2 (x, Double_Type xa[], Double_Type ya[])`

Description

  Use Akima spline interpolation with natural boundary conditions to determine the value of the second derivative at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

See Also

  `interp_linear_deriv2, interp_polynomial_deriv2, interp_cspline_deriv2, interp_cspline_periodic_deriv2, interp_akima_periodic_deriv2`

### interp_akima_periodic_deriv2

Synopsis

  Compute second derivative using an Akima spline

Usage

  `y = interp_cspline_deriv2 (x, Double_Type xa[], Double_Type ya[])`

Description

  Use Akima spline interpolation with periodic boundary conditions to determine the value of the second derivative at `x` given the points (`xa`, `ya`). The first argument, `x`, may be either a scalar or an array, and a result of the corresponding type will be returned.

See Also

  `interp_linear_deriv2, interp_polynomial_deriv2, interp_cspline_deriv2, interp_cspline_periodic_deriv2, interp_akima_deriv2, interp_akima_periodic_deriv2`

## 4.4 Integration via Interpolation

### interp_linear_integ

Synopsis

  Compute an integral using linear interpolation

Usage

  `y = interp_linear_integ (Double_Type xa[], Double_Type ya[], a, b)`

Description

  This function computes the integral from `a` to `b` of the linear interpolating function associated with the set of points (`xa`, `ya`). See `interp_linear` for more information about the interpolating function.

See Also

  `interp_polynomial_integ, interp_cspline_integ, interp_cspline_periodic_integ, interp_akima_integ, interp_akima_periodic_integ`

### interp_polynomial_integ

Synopsis

  Compute an integral using polynomial interpolation

Usage

  `y = interp_polynomial_integ (Double_Type xa[], Double_Type ya[], a, b)`

Description

  This function computes the integral from `a` to `b` of the polynomial interpolating function associated with the set of points (`xa`, `ya`). See `interp_polynomial` for more information about the interpolating function.

See Also

  `interp_linear_integ, interp_cspline_integ, interp_cspline_periodic_integ, interp_akima_integ, interp_akima_periodic_integ`

### interp_cspline_integ

Synopsis

  Compute an integral using a cubic spline

Usage

  `y = interp_cspline_integ (Double_Type xa[], Double_Type ya[], a, b)`

Description

  This function computes the integral from `a` to `b` of the cubic spline interpolating function associated with the set of points (`xa`, `ya`). See `interp_cspline` for more information about the interpolating function.

See Also

  `interp_linear_integ, interp_polynomial_integ, interp_cspline_periodic_integ, interp_akima_integ, interp_akima_periodic_integ`

### interp_cspline_periodic_integ

Synopsis

  Compute an integral using a cubic spline

Usage

  `y = interp_cspline_periodic_integ (Double_Type xa[], Double_Type ya[], a, b)`

Description

  This function computes the integral from `a` to `b` of the cubic spline interpolating function associated with the set of points (`xa`, `ya`). See `interp_cspline_periodic` for more information about the interpolating function.

See Also

  `interp_linear_integ, interp_polynomial_integ, interp_cspline_integ, interp_akima_integ, interp_akima_periodic_integ`

### interp_akima_integ

Synopsis

  Compute an integral using an Akima spline

Usage

  `y = interp_akima_integ (Double_Type xa[], Double_Type ya[], a, b)`

Description

  This function computes the integral from `a` to `b` of the Akima spline interpolating function associated with the set of points (`xa`, `ya`). See `interp_akima` for more information about the interpolating function.

See Also

  `interp_linear_integ, interp_polynomial_integ, interp_cspline_integ, interp_cspline_periodic_integ, interp_akima_periodic_integ`

### interp_akima_periodic_integ

Synopsis

  Compute an integral using an Akima spline

Usage

  `y = interp_cspline_integ (Double_Type xa[], Double_Type ya[], a, b)`

Description

  This function computes the integral from `a` to `b` of the Akima spline interpolating function associated with the set of points (`xa`, `ya`). See `interp_akima_periodic` for more information about the interpolating function.

See Also

  `interp_linear_integ, interp_polynomial_integ, interp_cspline_integ, interp_cspline_periodic_integ, interp_akima_integ`

## 4.5 Low-level Interpolation Routines

### interp_linear_init

Synopsis

  Compute a linear interpolation object

Usage

  `GSL_Interp_Type interp_linear_init (Double_Type_Type xa[], Double_Type_Type ya[])`

Description

  This function computes an interpolation object appropriate for linear interpolation on the specified `xa` and `ya` arrays.

See Also

  `interp_eval, interp_polynomial_init, interp_cspline_init, interp_cspline_periodic_init, interp_akima_init, interp_akima_periodic_init`

### interp_polynomial_init

Synopsis

  Compute a polynomial interpolation object

Usage

  `GSL_Interp_Type interp_polynomial_init (Double_Type xa[], Double_Type ya[])`

Description

  This function computes an interpolation object appropriate for polynomial interpolation on the specified `xa` and `ya` arrays.

See Also

  `interp_eval, interp_linear_init, interp_cspline_init, interp_cspline_periodic_init, interp_akima_init, interp_akima_periodic_init`

### interp_cspline_init

Synopsis

  Compute a cubic spline Interpolation object

Usage

  `GSL_Interp_Type interp_cspline_init (Double_Type xa[], Double_Type ya[])`

Description

  This function computes an interpolation object appropriate for cubic spline interpolation with natural boundary conditions on the specified `xa` and `ya` arrays.

See Also

  `interp_eval, interp_linear_init, interp_polynomial_init, interp_cspline_periodic_init, interp_akima_init, interp_akima_periodic_init`

### interp_cspline_periodic_init

Synopsis

  Compute a cubic spline interpolation object

Usage

  `GSL_Interp_Type interp_cspline_periodic_init (Double_Type xa[], Double_Type ya[])`

Description

  This function computes an interpolation object appropriate for cubic spline interpolation with periodic boundary conditions on the specified `xa` and `ya` arrays.

See Also

  `interp_eval, interp_linear_init, interp_polynomial_init, interp_cspline_init, interp_akima_init, interp_akima_periodic_init`

### interp_akima_init

Synopsis

  Compute an Akima spline interpolation object

Usage

  `GSL_Interp_Type interp_akima_init (Double_Type xa[], Double_Type ya[])`

Description

  This function computes an interpolation object appropriate for Akima spline interpolation with natural boundary conditions on the specified `xa` and `ya` arrays.

See Also

  `interp_eval, interp_linear_init, interp_polynomial_init, interp_cspline_init, interp_cspline_periodic_init, interp_akima_periodic_init`

### interp_akima_periodic_init

Synopsis

  Compute an Akima spline interpolation object

Usage

  `GSL_Interp_Type interp_akima_periodic_init (Double_Type xa[], Double_Type ya[])`

Description

  This function computes an interpolation object appropriate for Akima spline interpolation with periodic boundary conditions on the specified `xa` and `ya` arrays.

See Also

  `interp_eval, interp_linear_init, interp_polynomial_init, interp_cspline_init, interp_cspline_periodic_init, interp_akima_periodic`

### interp_eval

Synopsis

  Evaluate an interpolation object

Usage

  `y = interp_eval (GSL_Interp_Type c, x)`

Description

  Use the precomputed interpolation object `c` to interpolate its value at `x`, which may be either a scalar or an array. An interpolated value of the corresponding shape will be returned.

See Also

  `interp_linear_init, interp_eval_deriv, interp_eval_deriv2, interp_eval_integ`

### interp_eval_deriv

Synopsis

  Evaluate the derivative of an interpolation object

Usage

  `dydx = interp_eval_deriv (GSL_Interp_Type c, x)`

Description

  Use the precomputed interpolation object `c` to interpolate its first derivative at `x`, which may be either a scalar or an array. An interpolated value of the corresponding shape will be returned.

See Also

  `interp_linear_init, interp_eval, interp_eval_deriv2, interp_eval_integ`

### interp_eval_deriv2

Synopsis

  Evaluate the derivative of an interpolation object

Usage

  `d2ydx2 = interp_eval_deriv2 (GSL_Interp_Type c, x)`

Description

  Use the precomputed interpolation object `c` to interpolate its second derivative at `x`, which may be either a scalar or an array. An interpolated value of the corresponding shape will be returned.

See Also

  `interp_linear_init, interp_eval, interp_eval_deriv, interp_eval_integ`

### interp_eval_integ

Synopsis

  Compute the integral of an interpolation object

Usage

  `d2ydx2 = interp_eval_deriv2 (GSL_Interp_Type c, a, b)`

Description

  Use the precomputed interpolation object `c` to interpolate its integral from `a` to `b`.

See Also

  `interp_linear_init, interp_eval, interp_eval_deriv, interp_eval_deriv2`

Next Previous Contents