PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_interp_1d_spline (e01ba)
Purpose
nag_interp_1d_spline (e01ba) determines a cubic spline interpolant to a given set of data.
Syntax
Description
nag_interp_1d_spline (e01ba) determines a cubic spline
, defined in the range
, which interpolates (passes exactly through) the set of data points
, for
, where
and
. Unlike some other spline interpolation algorithms, derivative end conditions are not imposed. The spline interpolant chosen has
interior knots
, which are set to the values of
respectively. This spline is represented in its B-spline form (see
Cox (1975)):
where
denotes the normalized B-spline of degree
,
defined upon the knots
, and
denotes its coefficient, whose value is to be determined by the function.
The use of B-splines requires eight additional knots , ,
, ,
, ,
and to be specified; nag_interp_1d_spline (e01ba) sets the first four of these to and the last four to .
The algorithm for determining the coefficients is as described in
Cox (1975) except that
factorization is used instead of
decomposition. The implementation of the algorithm involves setting up appropriate information for the related
function
nag_fit_1dspline_knots (e02ba) followed by a call of that function. (See
nag_fit_1dspline_knots (e02ba) for further details.)
Values of the spline interpolant, or of its derivatives or definite integral, can subsequently be computed as detailed in
Further Comments.
References
Cox M G (1975) An algorithm for spline interpolation J. Inst. Math. Appl. 15 95–108
Cox M G (1977) A survey of numerical methods for data and function approximation The State of the Art in Numerical Analysis (ed D A H Jacobs) 627–668 Academic Press
Parameters
Compulsory Input Parameters
- 1:
– double array
-
must be set to , the th data value of the independent variable , for .
Constraint:
, for .
- 2:
– double array
-
must be set to , the th data value of the dependent variable , for .
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the arrays
x,
y. (An error is raised if these dimensions are not equal.)
, the number of data points.
Constraint:
.
Output Parameters
- 1:
– double array
-
.
The value of
, the th knot, for .
- 2:
– double array
-
.
The coefficient
of the B-spline , for . The remaining elements of the array are not used.
- 3:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
On entry, | , |
or | , |
or | . |
-
-
The
x-values fail to satisfy the condition
.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
The rounding errors incurred are such that the computed spline is an exact interpolant for a slightly perturbed set of ordinates
. The ratio of the root-mean-square value of the
to that of the
is no greater than a small multiple of the relative
machine precision.
Further Comments
The time taken by nag_interp_1d_spline (e01ba) is approximately proportional to .
All the
are used as knot positions except
and
. This choice of knots
(see
Cox (1977)) means that
is composed of
cubic arcs as follows. If
, there is just a single arc space spanning the whole interval
to
. If
, the first and last arcs span the intervals
to
and
to
respectively. Additionally if
, the
th arc, for
, spans the interval
to
.
After the call
[lamda, c, ifail] = e01ba(x, y, lck);
the following operations may be carried out on the interpolant
.
The value of
at
can be provided in the double variable
s by the call
[s, ifail] = e02bb(lamda, c, x);
(see
nag_fit_1dspline_eval (e02bb)).
The values of
and its first three derivatives at
can be provided in the double array
s
of dimension
, by the call
[s, ifail] = e02bc(lamda, c, x, left);
(see
nag_fit_1dspline_deriv (e02bc)).
Here
left
must specify whether the left- or right-hand value of the third derivative is required (see
nag_fit_1dspline_deriv (e02bc) for details).
The value of the integral of
over the range
to
can be provided in the
double variable
dint
by
[dint, ifail] = e02bd(lamda, c);
(see
nag_fit_1dspline_integ (e02bd)).
Example
This example sets up data from values of the exponential function in the interval to . nag_interp_1d_spline (e01ba) is then called to compute a spline interpolant to these data.
The spline is evaluated by
nag_fit_1dspline_eval (e02bb), at the data points and at points halfway between each adjacent pair of data points, and the spline values and the values of
are printed out.
Open in the MATLAB editor:
e01ba_example
function e01ba_example
fprintf('e01ba example results\n\n');
x = [0 0.2 0.4 0.6 0.75 0.9 1];
y = exp(x);
[lamda, c, ifail] = e01ba(x, y);
fprintf('\n j knot lamda(j+2) b-spline coeff c(j)\n\n');
j = 1;
fprintf('%4d%35.4f\n', j, c(1));
m = size(x,2);
for j = 2:m - 1;
fprintf('%4d%15.4f%20.4f\n', j, lamda(j+2), c(j));
end
fprintf('%4d%35.4f\n', m, c(m));
fprintf('\n R Abscissa Ordinate Spline\n\n');
for r = 1:m;
[fit, ifail] = e02bb( ...
lamda, c, x(r));
fprintf('%4d%15.4f%20.4f%20.4f\n', r, x(r), y(r), fit);
if r<m;
xarg = (x(r)+x(r+1))/2;
[fit, ifail] = e02bb( ...
lamda, c, xarg);
fprintf('%19.4f%40.4f\n', xarg, fit);
end
end
e01ba example results
j knot lamda(j+2) b-spline coeff c(j)
1 1.0000
2 0.0000 1.1336
3 0.4000 1.3726
4 0.6000 1.7827
5 0.7500 2.1744
6 1.0000 2.4918
7 2.7183
R Abscissa Ordinate Spline
1 0.0000 1.0000 1.0000
0.1000 1.1052
2 0.2000 1.2214 1.2214
0.3000 1.3498
3 0.4000 1.4918 1.4918
0.5000 1.6487
4 0.6000 1.8221 1.8221
0.6750 1.9640
5 0.7500 2.1170 2.1170
0.8250 2.2819
6 0.9000 2.4596 2.4596
0.9500 2.5857
7 1.0000 2.7183 2.7183
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015