E01AEF (PDF version)
E01 Chapter Contents
E01 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

E01AEF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

E01AEF constructs the Chebyshev series representation of a polynomial interpolant to a set of data which may contain derivative values.

2  Specification

SUBROUTINE E01AEF ( M, XMIN, XMAX, X, Y, IP, N, ITMIN, ITMAX, A, WRK, LWRK, IWRK, LIWRK, IFAIL)
INTEGER  M, IP(M), N, ITMIN, ITMAX, LWRK, IWRK(LIWRK), LIWRK, IFAIL
REAL (KIND=nag_wp)  XMIN, XMAX, X(M), Y(N), A(N), WRK(LWRK)

3  Description

Let m distinct values xi of an independent variable x be given, with xminxixmax, for i=1,2,,m. For each value xi, suppose that the value yi of the dependent variable y together with the first pi derivatives of y with respect to x are given. Each pi must therefore be a non-negative integer, with the total number of interpolating conditions, n, equal to m+i=1mpi.
E01AEF calculates the unique polynomial qx of degree n-1 (or less) which is such that qkxi=yik, for i=1,2,,m and k=0,1,,pi. Here q 0 xi means qxi. This polynomial is represented in Chebyshev series form in the normalized variable x-, as follows:
qx=12a0T0x-+a1T1x-++an-1Tn-1x-,
where
x-=2x-xmin-xmax xmax-xmin
so that -1x-1 for x in the interval xmin to xmax, and where Tix- is the Chebyshev polynomial of the first kind of degree i with argument x-.
(The polynomial interpolant can subsequently be evaluated for any value of x in the given range by using E02AKF. Chebyshev series representations of the derivative(s) and integral(s) of qx may be obtained by (repeated) use of E02AHF and E02AJF.)
The method used consists first of constructing a divided-difference table from the normalized x- values and the given values of y and its derivatives with respect to x-. The Newton form of qx is then obtained from this table, as described in Huddleston (1974) and Krogh (1970), with the modification described in Section 8.2. The Newton form of the polynomial is then converted to Chebyshev series form as described in Section 8.3.
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 Section 7). 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 parameter 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 routine returns the ‘best’ polynomial achieved before termination. For the definition of ‘best’ and details of iterative refinement and termination criteria, see Section 8.4.

4  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

5  Parameters

1:     M – INTEGERInput
On entry: m, the number of given values of the independent variable x.
Constraint: M1.
2:     XMIN – REAL (KIND=nag_wp)Input
3:     XMAX – REAL (KIND=nag_wp)Input
On entry: the lower and upper end points, respectively, of the interval xmin,xmax. If they are not determined by your problem, it is recommended that they be set respectively to the smallest and largest values among the xi.
Constraint: XMIN<XMAX.
4:     X(M) – REAL (KIND=nag_wp) arrayInput
On entry: the value of xi, for i=1,2,,m. The Xi need not be ordered.
Constraint: XMINXiXMAX, and the Xi must be distinct.
5:     Y(N) – REAL (KIND=nag_wp) arrayInput
On entry: the given values of the dependent variable, and derivatives, as follows:
The first p1+1 elements contain y1,y1 1 ,,y1 p1  in that order.
The next p2+1 elements contain y2,y2 1 ,,y2 p2  in that order.
The last pm+1 elements contain ym,ym 1 ,,ym pm  in that order.
6:     IP(M) – INTEGER arrayInput
On entry: pi, the order of the highest-order derivative whose value is given at xi, for i=1,2,,m. If the value of y only is given for some xi then the corresponding value of IPi must be zero.
Constraint: IPi0, for i=1,2,,M.
7:     N – INTEGERInput
On entry: n, the total number of interpolating conditions.
Constraint: N=M+ i=1 M IPi .
8:     ITMIN – INTEGERInput
9:     ITMAX – INTEGERInput
On entry: respectively the minimum and maximum number of iterations to be performed by the routine (for full details see Section 8.4). Setting ITMIN and/or ITMAX negative or zero invokes default value(s) of 2 and/or 10, respectively.
The default values will be satisfactory for most problems, but occasionally significant improvement will result from using higher values.
Suggested value: ITMIN=0 and ITMAX=0.
10:   A(N) – REAL (KIND=nag_wp) arrayOutput
On exit: Ai+1 contains the coefficient ai in the Chebyshev series representation of qx, for i=0,1,,n-1.
11:   WRK(LWRK) – REAL (KIND=nag_wp) arrayOutput
On exit: used as workspace, but see also Section 8.5.
12:   LWRK – INTEGERInput
On entry: the dimension of the array WRK as declared in the (sub)program from which E01AEF is called.
Constraint: LWRK7×N+5×ipmax+M+7 , where ipmax is the largest element of IPi, for i=1,2,,M.
13:   IWRK(LIWRK) – INTEGER arrayOutput
On exit: used as workspace, but see also Section 8.5.
14:   LIWRK – INTEGERInput
On entry: the dimension of the array IWRK as declared in the (sub)program from which E01AEF is called.
Constraint: LIWRK2×M+2.
15:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
IFAIL=1
On entry,M<1,
orNM+IP1+IP2++IPM,
orLWRK<7×N+5×ipmax+M+7 (see LWRK for the definition of ipmax),
orLIWRK<2×M+2.
IFAIL=2
On entry,IPi<0 for some i.
IFAIL=3
On entry,XMINXMAX,
orXi<XMIN for some i,
orXi>XMAX,
orXi=Xj for some ij.
IFAIL=4
Not all the performance indices are less than eight times the machine precision, although ITMAX iterations have been performed. Parameters A, WRK and IWRK relate to the best polynomial determined. A more accurate solution may possibly be obtained by increasing ITMAX and recalling the routine. See also Sections 7, 8.4 and 8.5.
IFAIL=5
The computation has been terminated because the iterative process appears to be diverging. (Parameters 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 Xi 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 E01BAF) 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 Sections 7, 8.4 and 8.5.

7  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 yi k -q k xi are available for inspection (see Section 8.5). To assess whether these are reasonable, however, it is necessary to relate them to the largest function and derivative values taken by qx over the interval xmin,xmax. The following performance indices aim to do this. Let the kth derivative of q with respect to the normalized variable x- be given by the Chebyshev series
12a0kT0x-+a1kT1x-++an-1-kkTn-1-kx-.
Let Ak denote the sum of the moduli of these coefficients (this is an upper bound on the kth derivative in the interval and is taken as a measure of the maximum size of this derivative), and define
Sk = max ik Ai .
Then if the root-mean-square value of the residuals of q k , scaled so as to relate to the normalized variable x-, is denoted by rk, the performance indices are defined by
Pk=rk/Sk,   for ​k=0,1,,maxipi.
It is expected that, in reasonable cases, they will all be less than (say) 8 times the machine precision (this is the accuracy criterion mentioned in Section 3), and in many cases will be of the order of machine precision or less.

8  Further Comments

8.1  Timing

Computation time is approximately proportional to it×n3, where it is the number of iterations actually used. (See Section 8.5.)

8.2  Divided-difference Strategy

In constructing each new coefficient in the Newton form of the polynomial, a new xi must be brought into the computation. The xi 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.

8.3  Conversion to Chebyshev Form

Conversion from the Newton form to Chebyshev series form is effected by evaluating the former at the n values of x- at which Tn-1x takes the value ±1, and then interpolating these n function values by a call of E02AFF, which provides the Chebyshev series representation of the polynomial with very small additional relative error.

8.4  Iterative Refinement

The iterative refinement process is performed as follows.
Firstly, an initial approximation, q1x say, is found by the technique described in Section 3. The rth step of the refinement process then consists of evaluating the residuals of the rth approximation qrx, and constructing an interpolant, dqrx, to these residuals. The next approximation qr+1x to the interpolating polynomial is then obtained as
qr+1x=qrx+dqrx.
This completes the description of the rth step.
The iterative process is terminated according to the following criteria. When a polynomial is found whose performance indices (as defined in Section 7) are all less than 8 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 r the sum of the moduli of the Chebyshev coefficients of dqrx is greater than that of qrx, it is concluded that the process is diverging and the process is terminated at once (qr+1x 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, rk (see Section 7) 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 Section 7) of the current best polynomial are all less than 8 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 8 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 qx.

8.5  Workspace Information

On successful exit, and also if IFAIL=4 or 5 on exit, the following information is contained in the workspace arrays WRK and IWRK:
WRKk+1, for k=0,1,,ipmax where ipmax=maxipi, contains the ratio of pk, the performance index relating to the kth derivative of the qx finally provided, to 8 times the machine precision.
WRKipmax+1+j, for j=1,2,,n, contains the jth residual, i.e., the value of yi k -q k xi, where i and k are the appropriate values corresponding to the jth element in the array Y (see the description of Y in Section 5).
IWRK1 contains the number of iterations actually performed in deriving qx.
If, on exit, IFAIL=4 or 5, the qx finally provided may still be adequate for your requirements. To assess this you should examine the residuals contained in WRKipmax+1+j, for j=1,2,,n, to see whether they are acceptably small.

9  Example

This example constructs an interpolant qx to the following data:
m=4, xmin=2, xmax=6, x1=2, p1=0, y1=1, x2=4, p2=1, y2=2, y2 1 =-1, x3=5, p3=0, y3=1, x4=6, p4=2, y4=2, y4 1 =4, y4 2 =-2.
The coefficients in the Chebyshev series representation of qx 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.

9.1  Program Text

Program Text (e01aefe.f90)

9.2  Program Data

Program Data (e01aefe.d)

9.3  Program Results

Program Results (e01aefe.r)


E01AEF (PDF version)
E01 Chapter Contents
E01 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012