NAG Library Routine Document

e02alf (dim1_minimax_polynomial)


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


Fortran Interface
Subroutine e02alf ( n, x, y, m, a, ref, ifail)
Integer, Intent (In):: n, m
Integer, Intent (Inout):: ifail
Real (Kind=nag_wp), Intent (In):: x(n), y(n)
Real (Kind=nag_wp), Intent (Out):: a(m+1), ref
C Header Interface
#include <nagmk26.h>
void  e02alf_ (const Integer *n, const double x[], const double y[], const Integer *m, double a[], double *ref, Integer *ifail)


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).


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


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).

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:
On entry, n=value.
Constraint: n1.
On entry, m=value.
Constraint: m<100.
On entry, m=value.
Constraint: m0.
On entry, m=value and n=value.
Constraint: m<n-1.
On entry, i=value, xi+1=value and xi=value.
Constraint: xi+1>xi.
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.
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.
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.


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.

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.

Further Comments

The time taken increases with m.


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.

Program Text

Program Text (e02alfe.f90)

Program Data

Program Data (e02alfe.d)

Program Results

Program Results (e02alfe.r)