Admin Production ni-theme
Current Publication

SpInterp

LabWindows/CVI

SpInterp

Advanced Analysis Library Only

AnalysisLibErrType SpInterp (double arrayX[], double arrayY[], double y2[], ssize_t numberOfElements, double xValue, double *interpolatedYValue);

Purpose

Performs a cubic spline interpolation of the function f at a value x_value, where x_value is in the same range as xi, given a tabulated function of the form yi = f(xi) for i = 0, 1, . . ., numberOfElements – 1, with x < xi + 1, and given the second derivatives that specify the interpolant at the numberOfElements nodes of arrayX. The Spline procedure supplies the second derivatives. You can then call SpInterp as many times as you need, assuming the same tabulated function. If x_value falls in the interval [xi, xi + 1], the interpolated value is as follows:

interpolatedValue = Ayi + Byi + 1 + Cy"i + Dy"i + 1

where

B = 1 - A

y" denotes the second derivative of arrayY.

Example Code

/* Choose ascending X-values. Pick corresponding Y-values randomly. Set boundary conditions and specify the cubic spline interpolant to run through the points. Pick an x in the same range as X and interpolate. Pick another x and interpolate again. */
double X[100], Y[100], Y2[100], b1, b2, x_val;
int n, i;
n = 100;
for(i=0; i<n; i++)
X[i] = i * 0.1;
WhiteNoise (n, 5.0, 17, Y);
b1=0.0;
b2=0.0;
Spline (X, Y, n, b1, b2, Y2);
x_val = 0.331;
SpInterp (X, Y, Y2, n, x_val, &Interp_Val);
x_val = 0.7698;
SpInterp (X, Y, Y2, n, x_val, &Interp_Val);

Parameters

Input
Name Type Description
arrayX double [] The known x-values for the planar function; these values must be in ascending order.
arrayY double [] The known y-values for the planar function.
secondDerivatives double [] Array of second derivatives that specify the interpolant.
numberOfElements ssize_t Number of elements in arrayX, arrayY, and secondDerivatives.
xValue double Value at which tabulated function is interpolated.
interpolatedYValue double * Interpolated value.

Return Value

Name Type Description
status AnalysisLibErrType A value that specifies the type of error that occurred. Refer to analysis.h for definitions of these constants.

Additional Information

Library: Advanced Analysis Library

Include file: analysis.h

LabWindows/CVI compatibility: LabWindows/CVI 3.1 and later

Example

Refer to analysis\interp.cws for an example of using the SpInterp function.