NAG FL Interface
e02alf (dim1_​minimax_​polynomial)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

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

2 Specification

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 <nag.h>
void  e02alf_ (const Integer *n, const double x[], const double y[], const Integer *m, double a[], double *ref, Integer *ifail)
The routine may be called by the names e02alf or nagf_fit_dim1_minimax_polynomial.

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
P(x) = a0 + a1x + a2 x2 + + am xm  
such that maxi|P(xi)-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 Integer Input
On entry: n, the number of data points.
Constraint: n1.
2: x(n) Real (Kind=nag_wp) array Input
On entry: the values of the x coordinates, xi, for i=1,2,,n.
Constraint: x1<x2<<xn.
3: y(n) Real (Kind=nag_wp) array Input
On entry: the values of the y coordinates, yi, for i=1,2,,n.
4: m Integer Input
On entry: m, where m is the degree of the polynomial to be found.
Constraint: 0m<min(100,n-1).
5: a(m+1) Real (Kind=nag_wp) array Output
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 Integer Input/Output
On entry: ifail must be set to 0, -1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of -1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value -1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. 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, x(i+1)=value and x(i)=value.
Constraint: x(i+1)>x(i).
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface 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)