Computes the value of a spline or the value of one of its derivatives.
#include <imsl.h>
float imsl_f_spline_value (float x, Imsl_f_spline *sp, ¼, 0)
The type double function is imsl_d_spline_value.
float x
(Input)
Evaluation point for the spline.
Imsl_f_spline *sp
(Input)
Pointer to the structure that represents the spline.
The value of a spline or one of its derivatives at the point x. If no value can be computed, NaN is returned.
#include <imsl.h>
float
imsl_f_spline_value
(float
x, Imsl_f_spline
*sp,
IMSL_DERIV, int
deriv,
IMSL_GRID, int n, float
*xvec,
float
**value,
IMSL_GRID_USER, int n, float
*xvec,
float
value_user[],
0)
IMSL_DERIV, int deriv
(Input)
Let d = deriv and let s
be the spline that is represented by the structure *sp. Then, this option
produces the d-th derivative of s at x, s(d)
(x).
Default: deriv = 0
IMSL_GRID, int n, float *xvec, float **value
(Input/Output)
The argument xvec is the array of
length n
containing the points at which the spline is to be evaluated. The d-th
derivative of the spline at the points in xvec is returned in
value.
IMSL_GRID_USER
int
n,
float
*xvec,
float
value_user[] (Input/Output)
The argument xvec is the array of
length n
containing the points at which the spline is to be evaluated. The d-th
derivative of the spline at the points in xvec is returned in
value_user.
The function imsl_f_spline_value computes the value of a spline or one of its derivatives. This function is based on the routine BVALUE by de Boor (1978, p. 144).
In this example, a cubic spline interpolant to a function f is computed. The values of this spline are then compared with the exact function 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
11
/*
Define function */
#define F(x)
(float)(sin(15.0*x))
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
F(x) Interpolant
Error\n");
for (i = NDATA/2; i < 3*NDATA/2;
i++){
x = (float) i
/(float)(2*NDATA-2);
y =
imsl_f_spline_value(x, sp, 0);
printf(" %6.3f %10.3f %10.3f %10.4f\n", x,
F(x),
y,
fabs(F(x)-y));
}
}
x
F(x) Interpolant
Error
0.250
-0.572
-0.549
0.0228
0.300
-0.978 -0.978
0.0000
0.350
-0.859
-0.843
0.0162
0.400
-0.279
-0.279
0.0000
0.450
0.450
0.441
0.0093
0.500
0.938
0.938
0.0000
0.550
0.923
0.903
0.0199
0.600
0.412
0.412
0.0000
0.650
-0.320
-0.315
0.0049
0.700
-0.880
-0.880
0.0000
0.750
-0.968
-0.938 0.0295
Recall that in the first example, a cubic spline interpolant to a function f is computed. The values of this spline are then compared with the exact function values. This example compares the values of the first derivatives.
#include <imsl.h>
#include
<stdio.h>
#include <math.h>
#define NDATA
11
/* Define function */
#define F(x)
(float)(sin(15.0*x))
#define FP(x)
(float)(15.*cos(15.0*x))
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
FP(x) Interpolant Deriv
Error\n");
for (i = NDATA/2; i < 3*NDATA/2;
i++) {
x = (float) i
/(float)(2*NDATA-2);
y =
imsl_f_spline_value(x, sp, IMSL_DERIV, 1,
0);
printf(" %6.3f
%10.3f %10.3f %10.4f \n", x, FP(x),
y,
fabs(FP(x)-y));
}
}
x FP(x)
Interpolant Deriv Error
0.250
-12.308
-12.559 0.2510
0.300
-3.162
-3.218 0.0560
0.350
7.681
7.796 0.1151
0.400
14.403
13.919 0.4833
0.450
13.395
13.530 0.1346
0.500
5.200
5.007 0.1926
0.550 -5.786
-5.840 0.0535
0.600 -13.667
-13.201 0.4660
0.650 -14.214
-14.393 0.1798
0.700
-7.133
-6.734 0.3990
0.750
3.775
3.911 0.1359
IMSL_KNOT_MULTIPLICITY Multiplicity of the knots cannot exceed the order of the spline.
IMSL_KNOT_NOT_INCREASING The knots must be nondecreasing.
|
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |