NAG CPP Interface
nagcpp::interp::dim1_spline (e01ba)

Settings help

CPP Name Style:



1 Purpose

dim1_spline determines a cubic spline interpolant to a given set of data.

2 Specification

#include "e01/nagcpp_e01ba.hpp"
template <typename X, typename Y, typename LAMDA, typename C>

void function dim1_spline(const X &x, const Y &y, LAMDA &&lamda, C &&c, OptionalE01BA opt)
template <typename X, typename Y, typename LAMDA, typename C>

void function dim1_spline(const X &x, const Y &y, LAMDA &&lamda, C &&c)

3 Description

dim1_spline determines a cubic spline s(x), defined in the range x1xxm, which interpolates (passes exactly through) the set of data points (xi,yi), for i=1,2,,m, where m4 and x1<x2<<xm. Unlike some other spline interpolation algorithms, derivative end conditions are not imposed. The spline interpolant chosen has m-4 interior knots λ5,λ6,,λm, which are set to the values of x3,x4,,xm-2 respectively. This spline is represented in its B-spline form (see Cox (1975)):
s(x)=i=1mciNi(x),  
where Ni(x) denotes the normalized B-spline of degree 3, defined upon the knots λi,λi+1,,λi+4, and ci denotes its coefficient, whose value is to be determined by the function.
The use of B-splines requires eight additional knots λ1, λ2, λ3, λ4, λm+1, λm+2, λm+3 and λm+4 to be specified; dim1_spline sets the first four of these to x1 and the last four to xm.
The algorithm for determining the coefficients is as described in Cox (1975) except that QR factorization is used instead of LU decomposition. The implementation of the algorithm involves setting up appropriate information for the related function e02baf (no CPP interface) followed by a call of that function. (See e02baf (no CPP interface) for further details.)
Values of the spline interpolant, or of its derivatives or definite integral, can subsequently be computed as detailed in Section 9.

4 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

5 Arguments

1: x(m) double array Input
On entry: x(i-1) must be set to xi, the ith data value of the independent variable x, for i=1,2,,m.
Constraint: x(i-1)<x(i), for i=1,2,,m-1.
2: y(m) double array Input
On entry: y(i-1) must be set to yi, the ith data value of the dependent variable y, for i=1,2,,m.
3: lamda(m+4) double array Output
On exit: the value of λi, the ith knot, for i=1,2,,m+4.
4: c(m+4) double array Output
On exit: the coefficient ci of the B-spline Ni(x), for i=1,2,,m. The remaining elements of the array are not used.
5: opt OptionalE01BA Input/Output
Optional parameter container, derived from Optional.

5.1Additional Quantities

1: m
m, the number of data points.
2: lck
The dimension of the arrays lamda and c.

6 Exceptions and Warnings

Errors or warnings detected by the function:
All errors and warnings have an associated numeric error code field, errorid, stored either as a member of the thrown exception object (see errorid), or as a member of opt.ifail, depending on how errors and warnings are being handled (see Error Handling for more details).
Raises: ErrorException
errorid=1
On entry, lck = value and m = value.
Constraint: lckm+4.
errorid=1
On entry, m = value.
Constraint: m4.
errorid=2
On entry, I=value, x[I-1]=value
and x[I-2]=value.
Constraint: x[I-1]>x[I-2].
errorid=10601
On entry, argument value must be a vector of size value array.
Supplied argument has value dimensions.
errorid=10601
On entry, argument value must be a vector of size value array.
Supplied argument was a vector of size value.
errorid=10601
On entry, argument value must be a vector of size value array.
The size for the supplied array could not be ascertained.
errorid=10602
On entry, the raw data component of value is null.
errorid=10603
On entry, unable to ascertain a value for value.
errorid=−99
An unexpected error has been triggered by this routine.
errorid=−399
Your licence key may have expired or may not have been installed correctly.
errorid=−999
Dynamic memory allocation failed.

7 Accuracy

The rounding errors incurred are such that the computed spline is an exact interpolant for a slightly perturbed set of ordinates yi+δyi. The ratio of the root-mean-square value of the δyi to that of the yi is no greater than a small multiple of the relative machine precision.

8 Parallelism and Performance

Please see the description for the underlying computational routine in this section of the FL Interface documentation.

9 Further Comments

The time taken by dim1_spline is approximately proportional to m.
All the xi are used as knot positions except x2 and xm-1. This choice of knots (see Cox (1977)) means that s(x) is composed of m-3 cubic arcs as follows. If m=4, there is just a single arc space spanning the whole interval x1 to x4. If m5, the first and last arcs span the intervals x1 to x3 and xm-2 to xm respectively. Additionally if m6, the ith arc, for i=2,3,,m-4, spans the interval xi+1 to xi+2.
After calling dim1_spline the following operations may be carried out on the interpolant s(x).
The value of s(x) at x=x can be provided in the real variable s by calling dim1_​spline_​eval.
The values of s(x) and its first three derivatives at x=x can be provided in the real array s of dimension 4, by calling dim1_​spline_​deriv.
In the call to dim1_​spline_​deriv, left must specify whether the left- or right-hand value of the third derivative is required (see e02bcf (no CPP interface) for details).
The value of the integral of s(x) over the range x1 to xm can be provided in the real variable dint by calling dim1_​spline_​integ.

10 Example

This example sets up data from 7 values of the exponential function in the interval 0 to 1. dim1_spline is then called to compute a spline interpolant to these data.
The spline is evaluated by dim1_​spline_​eval, at the data points and at points halfway between each adjacent pair of data points, and the spline values and the values of ex are printed out.

10.1 Example Program

Source File Data Results
ex_e01ba.cpp None ex_e01ba.r