next up previous contents index
Next: Plotting graphs Up: Mathematical functions Previous: Minimisation and root-finding   Contents   Index

Determining a cubic spline interpolant, SplineCL


Spline interpolation

SplineCL determines the coefficients for a cubic spline interpolating function from a sequence of data-points $(x_i,y_i)_{i=1}^n$. It determines the coefficients $(b_i, c_i, d_i)_{i=1}^n$ in the piecewise cubic interpolating function:

\begin{displaymath}
\m y(x)=y_i + b_i(x-x_i) + c_i(x-x_i)^2 + d_i(x-x_i)^3\quad\mbox{for $x\in [x_i,x_{i+1})$.}
\end{displaymath}

(The coefficients $b_n$, $c_n$ and $d_n$ are not used in the interpolating function but are used as workspace by SplineCL.) The interpolating function passes through the data points and has a continuous first and second derivative everywhere. Once calculated, the interpolating function can be evaluated using SplineValCL.

  void SplineCL ( int n,
  double *x,
  double *y,
  double *b,
  double *c,
  double *d);

  n The number of data points.
  x Array holding the sequence $x_1,\ldots{,}\,x_n$.
  y Array holding the sequence $y_1,\ldots{,}\,y_n$.
  b Array to hold the coefficients $b_1,\ldots{,}\,b_n$.
  c Array to hold the coefficients $c_1,\ldots{,}\,c_n$.
  d Array to hold the coefficients $d_1,\ldots{,}\,d_n$.

The example program b04splin.c demonstrates the use of SplineCL.


Evaluating the interpolant, SplineValCL

Once SplineCL has been used to calculate the cubic spline interpolating function for a dataset $(x_i,y_i)_{i=1}^n$, the routine SplineValCL can be used to evaluate it at an arbitrary point.

  double SplineValCL ( int n,
  double x,
  double *xpts,
  double *y,
  double *b,
  double *c,
  double *d);

  n The number of data points.
  x The point at which the interpolating function is to be evaluated.
  xpts Array holding the sequence $x_1,\ldots{,}\,x_n$.
  y Array holding the sequence $y_1,\ldots{,}\,y_n$.
  b Array to hold the coefficients $b_1,\ldots{,}\,b_n$.
  c Array to hold the coefficients $c_1,\ldots{,}\,c_n$.
  d Array to hold the coefficients $d_1,\ldots{,}\,d_n$.

The example program b04splin.c demonstrates the use of SplineValCL.


next up previous contents index
Next: Plotting graphs Up: Mathematical functions Previous: Minimisation and root-finding   Contents   Index
CATAM admin 2010-02-23