PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_interp_1d_cheb (e01ae)
Purpose
nag_interp_1d_cheb (e01ae) constructs the Chebyshev series representation of a polynomial interpolant to a set of data which may contain derivative values.
Syntax
[
a,
wrk,
iwrk,
ifail] = e01ae(
xmin,
xmax,
x,
y,
ip,
lwrk,
liwrk, 'm',
m, 'itmin',
itmin, 'itmax',
itmax)
[
a,
wrk,
iwrk,
ifail] = nag_interp_1d_cheb(
xmin,
xmax,
x,
y,
ip,
lwrk,
liwrk, 'm',
m, 'itmin',
itmin, 'itmax',
itmax)
Description
Let distinct values of an independent variable be given, with , for . For each value , suppose that the value of the dependent variable together with the first derivatives of with respect to are given. Each must therefore be a non-negative integer, with the total number of interpolating conditions, , equal to .
nag_interp_1d_cheb (e01ae) calculates the unique polynomial
of degree
(or less) which is such that
, for
and
. Here
means
. This polynomial is represented in Chebyshev series form in the normalized variable
, as follows:
where
so that
for
in the interval
to
, and where
is the Chebyshev polynomial of the first kind of degree
with argument
.
(The polynomial interpolant can subsequently be evaluated for any value of
in the given range by using
nag_fit_1dcheb_eval2 (e02ak). Chebyshev series representations of the derivative(s) and integral(s) of
may be obtained by (repeated) use of
nag_fit_1dcheb_deriv (e02ah) and
nag_fit_1dcheb_integ (e02aj).)
The method used consists first of constructing a divided-difference table from the normalized
values and the given values of
and its derivatives with respect to
. The Newton form of
is then obtained from this table, as described in
Huddleston (1974) and
Krogh (1970), with the modification described in
Divided-difference Strategy. The Newton form of the polynomial is then converted to Chebyshev series form as described in
Conversion to Chebyshev Form.
Since the errors incurred by these stages can be considerable, a form of iterative refinement is used to improve the solution. This refinement is particularly useful when derivatives of rather high order are given in the data. In reasonable examples, the refinement will usually terminate with a certain accuracy criterion satisfied by the polynomial (see
Accuracy). In more difficult examples, the criterion may not be satisfied and refinement will continue until the maximum number of iterations (as specified by the input argument
itmax) is reached.
In extreme examples, the iterative process may diverge (even though the accuracy criterion is satisfied): if a certain divergence criterion is satisfied, the process terminates at once. In all cases the function returns the ‘best’ polynomial achieved before termination. For the definition of ‘best’ and details of iterative refinement and termination criteria, see
Iterative Refinement.
References
Huddleston R E (1974) CDC 6600 routines for the interpolation of data and of data with derivatives SLL-74-0214 Sandia Laboratories (Reprint)
Krogh F T (1970) Efficient algorithms for polynomial interpolation and numerical differentiation Math. Comput. 24 185–190
Parameters
Compulsory Input Parameters
- 1:
– double scalar
- 2:
– double scalar
-
The lower and upper end points, respectively, of the interval . If they are not determined by your problem, it is recommended that they be set respectively to the smallest and largest values among the .
Constraint:
.
- 3:
– double array
-
the value of , for . The need not be ordered.
Constraint:
, and the must be distinct.
- 4:
– double array
-
n, the dimension of the array, must satisfy the constraint
.
The given values of the dependent variable, and derivatives, as follows:
The first elements contain in that order.
The next elements contain in that order.
The last elements contain in that order.
- 5:
– int64int32nag_int array
-
, the order of the highest-order derivative whose value is given at , for . If the value of only is given for some then the corresponding value of must be zero.
Constraint:
, for .
- 6:
– int64int32nag_int scalar
-
The dimension of the array
wrk.
Constraint:
, where is the largest element of , for .
- 7:
– int64int32nag_int scalar
-
The dimension of the array
iwrk.
Constraint:
.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the arrays
x,
ip. (An error is raised if these dimensions are not equal.)
, the number of given values of the independent variable .
Constraint:
.
- 2:
– int64int32nag_int scalar
- 3:
– int64int32nag_int scalar
Suggested value:
and .
Default:
Respectively the minimum and maximum number of iterations to be performed by the function (for full details see
Iterative Refinement). Setting
itmin and/or
itmax negative or zero invokes default value(s) of
and/or
, respectively.
The default values will be satisfactory for most problems, but occasionally significant improvement will result from using higher values.
Output Parameters
- 1:
– double array
-
.
contains the coefficient in the Chebyshev series representation of , for .
- 2:
– double array
-
Used as workspace, but see also
Workspace Information.
- 3:
– int64int32nag_int array
-
Used as workspace, but see also
Workspace Information.
- 4:
– 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:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
-
-
On entry, | , |
or | , |
or | (see lwrk for the definition of ), |
or | . |
-
-
On entry, | for some . |
-
-
On entry, | , |
or | for some , |
or | , |
or | for some . |
- W
-
Not all the performance indices are less than eight times the
machine precision, although
itmax iterations have been performed. Arguments
a,
wrk and
iwrk relate to the best polynomial determined. A more accurate solution may possibly be obtained by increasing
itmax and recalling the function. See also
Accuracy,
Iterative Refinement and
Workspace Information.
-
-
The computation has been terminated because the iterative process appears to be diverging. (Arguments
a,
wrk and
iwrk relate to the best polynomial determined.) Thus the problem specified by your data is probably too ill-conditioned for the solution to be satisfactory. This may result from some of the
being very close together, or from the number of interpolating conditions,
n, being large. If in such cases the conditions do not involve derivatives, you are likely to obtain a much more satisfactory solution to your problem either by cubic spline interpolation (see
nag_interp_1d_spline (e01ba)) or by curve-fitting with a polynomial or spline in which the number of coefficients is less than
n, preferably much less if
n is large (see
Chapter E02). But see
Accuracy,
Iterative Refinement and
Workspace Information.
-
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
A complete error analysis is not currently available, but the method gives good results for reasonable problems.
It is important to realise that for some sets of data, the polynomial interpolation problem is ill-conditioned. That is, a small perturbation in the data may induce large changes in the polynomial, even in exact arithmetic. Though by no means the worst example, interpolation by a single polynomial to a large number of function values given at points equally spaced across the range is notoriously ill-conditioned and the polynomial interpolating such a dataset is prone to exhibit enormous oscillations between the data points, especially near the ends of the range. These will be reflected in the Chebyshev coefficients being large compared with the given function values. A more familiar example of ill-conditioning occurs in the solution of certain systems of linear algebraic equations, in which a small change in the elements of the matrix and/or in the components of the right-hand side vector induces a relatively large change in the solution vector. The best that can be achieved in these cases is to make the residual vector small in some sense. If this is possible, the computed solution is exact for a slightly perturbed set of data. Similar considerations apply to the interpolation problem.
The residuals
are available for inspection
(see
Workspace Information).
To assess whether these are reasonable, however, it is necessary to relate them to the largest function and derivative values taken by
over the interval
. The following performance indices aim to do this. Let the
th derivative of
with respect to the normalized variable
be given by the Chebyshev series
Let
denote the sum of the moduli of these coefficients (this is an upper bound on the
th derivative in the interval and is taken as a measure of the maximum size of this derivative), and define
Then if the root-mean-square value of the residuals of
, scaled so as to relate to the normalized variable
, is denoted by
, the performance indices are defined by
It is expected that, in reasonable cases, they will all be less than (say)
times the
machine precision (this is the accuracy criterion mentioned in
Description), and in many cases will be of the order of
machine precision or less.
Further Comments
Timing
Computation time is approximately proportional to
, where
is the number of iterations actually used.
(See
Workspace Information.)
Divided-difference Strategy
In constructing each new coefficient in the Newton form of the polynomial, a new must be brought into the computation. The chosen is that which yields the smallest new coefficient. This strategy increases the stability of the divided-difference technique, sometimes quite markedly, by reducing errors due to cancellation.
Conversion to Chebyshev Form
Conversion from the Newton form to Chebyshev series form is effected by evaluating the former at the
values of
at which
takes the value
, and then interpolating these
function values by a call of
nag_fit_1dcheb_glp (e02af), which provides the Chebyshev series representation of the polynomial with very small additional relative error.
Iterative Refinement
The iterative refinement process is performed as follows.
Firstly, an initial approximation,
say, is found by the technique described in
Description. The
th step of the refinement process then consists of evaluating the residuals of the
th approximation
, and constructing an interpolant,
, to these residuals. The next approximation
to the interpolating polynomial is then obtained as
This completes the description of the
th step.
The iterative process is terminated according to the following criteria. When a polynomial is found whose performance indices (as defined in
Accuracy) are all less than
times the
machine precision, the process terminates after
itmin further iterations (or after a total of
itmax iterations if that occurs earlier). This will occur in most reasonable problems. The extra iterations are to allow for the possibility of further improvement. If no such polynomial is found, the process terminates after a total of
itmax iterations. Both these criteria are over-ridden, however, in two special cases. Firstly, if for some value of
the sum of the moduli of the Chebyshev coefficients of
is greater than that of
, it is concluded that the process is diverging and the process is terminated at once (
is not computed).
Secondly, if at any stage, the performance indices are all computed as zero, again the process is terminated at once.
As the iterations proceed, a record is kept of the best polynomial. Subsequently, at the end of each iteration, the new polynomial replaces the current best polynomial if it satisfies two conditions (otherwise the best polynomial remains unchanged). The first condition is that at least one of its root-mean-square residual values,
(see
Accuracy) is smaller than the corresponding value for the current best polynomial. The second condition takes two different forms according to whether or not the performance indices (see
Accuracy) of the current best polynomial are all less than
times the
machine precision. If they are, then the largest performance index of the new polynomial is required to be less than that of the current best polynomial. If they are not, the number of indices which are less than
times the
machine precision must not be smaller than for the current best polynomial. When the iterative process is terminated, it is the polynomial then recorded as best, which is returned to you as
.
Workspace Information
On successful exit, and also if
or
on exit, the following information is contained in the workspace arrays
wrk and
iwrk:
, for
where
, contains the ratio of
, the performance index relating to the
th derivative of the
finally provided, to
times the
machine precision.
, for
, contains the
th residual, i.e., the value of
, where
and
are the appropriate values corresponding to the
th element in the array
y (see the description of
y in
Arguments).
contains the number of iterations actually performed in deriving .
If, on exit, or , the finally provided may still be adequate for your requirements. To assess this you should examine the residuals contained in , for , to see whether they are acceptably small.
Example
This example constructs an interpolant
to the following data:
The coefficients in the Chebyshev series representation of
are printed, and also the residuals corresponding to each of the given function and derivative values.
This program is written in a generalized form which can read any number of data-sets.
Open in the MATLAB editor:
e01ae_example
function e01ae_example
fprintf('e01ae example results\n\n');
xmin = 2;
xmax = 6;
ip = int64([0 1 0 2]);
x = [2 4 5 6];
y = [1 ...
2 -1 ...
1 ...
2 4 -2];
lwrk = int64(77);
liwrk = int64(10);
[a, wrk, iwrk, ifail] = e01ae( ...
xmin, xmax, x, y, ip, lwrk, liwrk);
n = size(a,1);
fprintf('Total number of interpolating conditions = %3d\n', n);
fprintf('\nInterpolating polynomial\n\n i a_i\n');
fprintf('%4d%20.4f\n',[[0:n-1]' a]');
fprintf('\n i x_i order(k) y^k Residual\n');
restol = x02aj()*100;
iy = 0;
ipmax = max(ip);
m = size(ip,2);
ires = ipmax + 1;
for i = 1:m
iy = iy + 1;
ires = ires + 1;
if abs(wrk(ires))>restol
fprintf('%3d%6.1f%7d%11.1f%19.10e\n', i, x(i), 0, y(iy), wrk(ires));
else
fprintf('%3d%6.1f%7d%11.1f%11s\n', i, x(i), 0, y(iy), ' - ');
end
for j = 1:ip(i)
iy = iy + 1;
ires = ires + 1;
if abs(wrk(ires))>restol
fprintf('%16d%11.1f%19.10e\n', j, y(iy), wrk(ires));
else
fprintf('%16d%11.1f%11s\n', j, y(iy), ' - ');
end
end
end
e01ae example results
Total number of interpolating conditions = 7
Interpolating polynomial
i a_i
0 9.1250
1 -4.5781
2 0.4609
3 2.8516
4 -2.8125
5 2.2266
6 -0.7109
i x_i order(k) y^k Residual
1 2.0 0 1.0 -
2 4.0 0 2.0 -
1 -1.0 -
3 5.0 0 1.0 -
4 6.0 0 2.0 -
1 4.0 -
2 -2.0 -
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015