E02ALF (PDF version)
E02 Chapter Contents
E02 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

E02ALF

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

E02ALF calculates a minimax polynomial fit to a set of data points.

2  Specification

SUBROUTINE E02ALF ( N, X, Y, M, A, REF, IFAIL)
INTEGER  N, M, IFAIL
REAL (KIND=nag_wp)  X(N), Y(N), A(M+1), REF

3  Description

Given a set of data points xi,yi, for i=1,2,,n, E02ALF uses the exchange algorithm to compute an mth-degree polynomial
Px = a0 + a1x + a2 x2 + + am xm  
such that maxiPxi-yi is a minimum.
The routine also returns a number whose absolute value is the final reference deviation (see Section 5). The routine is an adaptation of Boothroyd (1967).

4  References

Boothroyd J B (1967) Algorithm 318 Comm. ACM 10 801
Stieffel E (1959) Numerical methods of Tchebycheff approximation On Numerical Approximation (ed R E Langer) 217–232 University of Wisconsin Press

5  Arguments

1:     N – INTEGERInput
On entry: n, the number of data points.
Constraint: N1.
2:     XN – REAL (KIND=nag_wp) arrayInput
On entry: the values of the x coordinates, xi, for i=1,2,,n.
Constraint: x1<x2<<xn.
3:     YN – REAL (KIND=nag_wp) arrayInput
On entry: the values of the y coordinates, yi, for i=1,2,,n.
4:     M – INTEGERInput
On entry: m, where m is the degree of the polynomial to be found.
Constraint: 0M<min100,N-1.
5:     AM+1 – REAL (KIND=nag_wp) arrayOutput
On exit: the coefficients ai of the minimax polynomial, for i=0,1,,m.
6:     REF – REAL (KIND=nag_wp)Output
On exit: the final reference deviation, i.e., the maximum deviation of the computed polynomial evaluated at xi from the reference values yi, for i=1,2,,n. REF may return a negative value which indicates that the algorithm started to cycle due to round-off errors.
7:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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, N=value.
Constraint: N1.
IFAIL=2
On entry, M=value.
Constraint: M<100.
On entry, M=value.
Constraint: M0.
On entry, M=value and N=value.
Constraint: M<N-1.
IFAIL=3
On entry, i=value, Xi+1=value and Xi=value.
Constraint: Xi+1>Xi.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7  Accuracy

This is dependent on the given data points and on the degree of the polynomial. The data points should represent a fairly smooth function which does not contain regions with markedly different behaviours. For large numbers of data points (N>100, say), rounding error will affect the computation regardless of the quality of the data; in this case, relatively small degree polynomials (MN) may be used when this is consistent with the required approximation. A limit of 99 is placed on the degree of polynomial since it is known from experiment that a complete loss of accuracy often results from using such high degree polynomials in this form of the algorithm.

8  Parallelism and Performance

E02ALF makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9  Further Comments

The time taken increases with m.

10  Example

This example calculates a minimax fit with a polynomial of degree 5 to the exponential function evaluated at 21 points over the interval 0,1. It then prints values of the function and the fitted polynomial.

10.1  Program Text

Program Text (e02alfe.f90)

10.2  Program Data

Program Data (e02alfe.d)

10.3  Program Results

Program Results (e02alfe.r)


E02ALF (PDF version)
E02 Chapter Contents
E02 Chapter Introduction
NAG Library Manual

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