Computes a tension-continuity-bias (TCB) cubic spline interpolant. This is also called a Kochanek-Bartels spline and is a generalization of the Catmull–Rom spline.
The type Imsl_d_ppoly function is imsl_d_cub_spline_tcb.
Required Arguments
intndata (Input) Number of data points.
floatxdata[] (Input) Array with ndata components containing the abscissas of the interpolation problem.
floatfdata[] (Input) Array with ndata components containing the ordinates for the interpolation problem.
Return Value
A pointer to the structure that represents the interpolant. If an interpolant cannot be computed, NULL is returned. To release this space, use imsl_free.
IMSL_TENSION, floattension[] (Input) Sets the tension values at the data points. The array tension is of length ndata and contains tension values in the interval [-1,1]. For each point, if the tension value is near +1 the curve is tightened at that point. If it is near -1, the curve is slack. Default: All values of tension are zero.
IMSL_CONTINUITY, floatcontinuity[] (Input) Sets the continuity values at the data points. The array continuity is of length ndata and contains continuity values in the interval [-1,1]. For each point, if the continuity value is zero the curve is C1 at that point. Otherwise the curve has a corner at that point, but is still continuous (C0). Default: All values of continuity are zero.
IMSL_BIAS, floatbias[] (Input) Sets the bias values at the data points. The array bias is of length ndata and contains bias values in the interval [-1,1]. For each point, if the bias value is zero the left and right side tangents are equally weighted. If the value is near +1 the left-side tangent dominates. If the value is near -1 the right-side tangent dominates. Default: All values of bias are zero.
IMSL_LEFT, floatleft (Input) Sets the value of the tangent at the leftmost endpoint. Default: left = 0.
IMSL_RIGHT, floatright (Input) Sets the value of the tangent at the rightmost endpoint. Default: right = 0.
Description
The function imsl_f_cub_spline_tcb computes the Kochanek-Bartels spline, a piecewise cubic Hermite spline interpolant to a set of data points {xi, fi} for I = 0, …, ndata-1. The breakpoints of the spline are the abscissas. As with all of the univariate interpolation functions, the abscissas need not be sorted.
The {xi} values are the knots, so the i-th interval is [xi, xi+1]. (To simplify the explanation, it is assumed that the data points are given in increasing order.) The cubic Hermite in the i-th segment has a starting value of fi and an ending value of fi+1. Its incoming tangent is
where ti is the i-th tension value, ci is the i-th continuity value, and bi is the i-th bias value. Its outgoing tangent is
The optional arguments left and right are used at the endpoints:
and
Both left and right default to zero.
The spline has a continuous first derivative (is C1) if at each data point the left and right tangents are equal. This is true if the continuity parameters, ci, are all zero. For any values of the parameters the spline is continuous (C0).
If ti = ci = bi = 0 for all i, then the curve is the Catmull-Rom spline.
The following chart shows the same data points interpolated with different parameter values. All of the tension, continuity and bias parameters are zero except for the labeled parameter, which has the indicated value at all data points.
Tension controls how sharply the spline bends at the data points. If tension is near +1, the curve tightens. If tension is near -1, the curve slackens.
The continuity parameter controls the continuity of the first derivative. If continuity is zero, the spline’s first derivative is continuous, so the spline is C1.
The bias parameter controls the weighting of the left and right tangents. If zero, the tangents are equally weighted. If the bias parameter is near +1, the left tangent dominates. If the bias parameter is near -1, the right tangent dominates.
Figure 3.3 — Data Points Interpolated with Different Parameter Values
Examples
Example 1
This example interpolates to a set of points. At x = 3 the continuity and tension parameters are -1. At all other points, they are zero. Interpolated values are then printed.
It is possible to use an interpolating spline for approximation by using an optimization function to compute its parameters. In this example a series of n interest rates, ri, for different maturities, xi, is given, {xi, ri} for i = 0, …, n-1. Since the dates are given on a widely varying time scale, the base 10 logarithm of the dates is used for interpolation.
A TCB spline is constructed using a subset of the given data points for knot locations, {pi , qi}, for i = 0, …, m-1. The p values are a subset of the log10xi values. The q values are to be determined by the optimizer. The spline has non-zero values of the continuity parameter, ci, for i = 0, …, m-1.
The optimization problem finds the spline, , which interpolates the points {pi, qi} and has continuity parameters, c, and specified left and right parameters.
The optimization problem is
subject to the bounds, for all i.
The function constrained_nlp is used as the optimizer. The unknowns q, c, left and right are packed into the array x, respectively.
#include <imsl.h>
#include <stdio.h>
#include <math.h>
void fcn(int n, double x[], int iact, double *result, int *ierr);