spline_integral
Computes the integral of a spline.
Synopsis
#include <imsl.h>
float imsl_f_spline_integral (float a, float b, Imsl_f_spline *sp)
The type double function is imsl_d_spline_integral.
Required Arguments
float a (Input)
The lower limit of integration.
float b (Input)
Endpoints for integration.
Imsl_f_spline *sp (Input)
Pointer to the structure that represents the spline.
Return Value
The integral of a spline. If no value can be computed, then NaN is returned.
Description
The function imsl_f_spline_integral computes the integral of a spline from a to b
This routine uses the identity (22) on page 151 of de Boor (1978).
Example
In this example, a cubic spline interpolant to a function f is computed. The values of the integral of this spline are then compared with the exact integral values. Since the default settings are used, the interpolant is determined by the “not-a-knot” condition (see de Boor 1978).
#include <imsl.h>
#include <stdio.h>
#include <math.h>
#define NDATA 21
/* Define function */
#define F(x) (float)(sin(15.0*x))
/* Integral from 0 to x */
#define FI(x) (float)((1.-cos(15.0*x))/15.)
int main()
{
int i;
float fdata[NDATA], xdata[NDATA], x, y;
Imsl_f_spline *sp;
/* Set up a grid */
for (i = 0; i < NDATA; i++) {
xdata[i] = (float)i /((float)(NDATA-1));
fdata[i] = F(xdata[i]);
}
/* Compute cubic spline interpolant */
sp = imsl_f_spline_interp (NDATA, xdata, fdata, 0);
/* Print results */
printf(" x FI(x) Interpolant Integral Error\n");
for (i = NDATA/2; i < 3*NDATA/2; i++) {
x = (float) i /(float)(2*NDATA-2);
y = imsl_f_spline_integral(0.0, x, sp);
printf(" %6.3f %10.3f %10.3f %10.4f \n", x, FI(x), y,
fabs(FI(x)-y));
}
}
Output
x FI(x) Interpolant Integral Error
0.250 0.121 0.121 0.0001
0.275 0.104 0.104 0.0001
0.300 0.081 0.081 0.0001
0.325 0.056 0.056 0.0001
0.350 0.033 0.033 0.0001
0.375 0.014 0.014 0.0002
0.400 0.003 0.003 0.0002
0.425 0.000 0.000 0.0002
0.450 0.007 0.007 0.0002
0.475 0.022 0.022 0.0001
0.500 0.044 0.044 0.0001
0.525 0.068 0.068 0.0001
0.550 0.092 0.092 0.0001
0.575 0.113 0.113 0.0001
0.600 0.127 0.128 0.0001
0.625 0.133 0.133 0.0001
0.650 0.130 0.130 0.0001
0.675 0.118 0.118 0.0001
0.700 0.098 0.098 0.0001
0.725 0.075 0.075 0.0001
0.750 0.050 0.050 0.0001
Warning Errors
IMSL_SPLINE_SMLST_ELEMNT |
The data arrays xdata and ydata must satisfy datai ≤ torder-1, for i = 1, …, num_data. |
IMSL_SPLINE_EQUAL_LIMITS |
The upper and lower endpoints of integration are equal. The indefinite integral is zero. |
IMSL_LIMITS_LOWER_TOO_SMALL |
The left endpoint is less than torder-1. Integration occurs only from torder-1 to b. |
IMSL_LIMITS_UPPER_TOO_SMALL |
The right endpoint is less than torder-1. Integration occurs only from torder-1 to a. |
IMSL_LIMITS_UPPER_TOO_BIG |
The right endpoint is greater than tspline_space_dim-1. Integration occurs only from a to tspline_space_dim-1. |
IMSL_LIMITS_LOWER_TOO_BIG |
The left endpoint is greater than tspline_space_dim-1. Integration occurs only from b to tspline_space_dim-1. |
Fatal Errors
IMSL_KNOT_MULTIPLICITY |
Multiplicity of the knots cannot exceed the order of the spline. |
IMSL_KNOT_NOT_INCREASING |
The knots must be nondecreasing. |