PolyInterp

Advanced Analysis Library Only

AnalysisLibErrType PolyInterp (double arrayX[], double arrayY[], int numberOfElements, double x_value, double *interpolatedYValue, double *errorEstimate);

Purpose

Calculates the value of the unique polynomial P of degree (numberOfElements — 1) passing through the numberOfElements points (xi, f(xi)) at x_value and returns an estimate of the error in the interpolation, given a set of numberOfElements points (xi, f(xi)) in the plane where f is some function and given a value x_value at which f is interpolated or extrapolated.

All input arrays should be the same size. If the value of x_value is in the range of arrayX, PolyInterp performs interpolation; otherwise, it performs extrapolation. If x_value is too far from the range of arrayX, errorEstimate might be large, and PolyInterp would not produce a satisfactory extrapolation.

Example

/* Pick points randomly, pick an x in the range of X-values, run a polynomial through the points, and interpolate at x_val. */
double X[10], Y[10], Interp_Val, Error, x_val, high, low;
n, i;
n = 10;
WhiteNoise (n, 5.0, 17, X);
WhiteNoise (n, 5.0, 17, Y);
high = X[0];
low = X[0];
for(i=0; i<n; i++) {

if (X[i] > high) high = X[i];
if (X[i] < low) low = X[i];

}
x_val = (high + low)/2.0;
PolyInterp (x, y, n, x_val, &Interp_Val, &Error);

Parameters

Input
Name Type Description
arrayX double-precision array Known x-values for the planar function.
arrayY double-precision array The known y-values for the planar function.
numberOfElements integer Number of points in arrayX and in arrayY.
x_value double-precision Value at which the function is interpolated or extrapolated.
Output
Name Type Description
interpolatedYValue double-precision A calculated estimate of the y-value corresponding to the given x_value for the tabulated function.
errorEstimate double-precision Estimate of the error in the interpolation.

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.