NAG C Library Function Document

nag_1d_minimax_polynomial (e02alc)


nag_1d_minimax_polynomial (e02alc) calculates a minimax polynomial fit to a set of data points.


#include <nag.h>
#include <nage02.h>
void  nag_1d_minimax_polynomial (Integer n, const double x[], const double y[], Integer m, double a[], double *ref, NagError *fail)


Given a set of data points xi,yi, for i=1,2,,n, nag_1d_minimax_polynomial (e02alc) 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 function also returns a number whose absolute value is the final reference deviation (see Section 5). The function 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:     x[n] const doubleInput
On entry: the values of the x coordinates, xi, for i=1,2,,n.
Constraint: x1<x2<<xn.
3:     y[n] const doubleInput
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:     a[m+1] doubleOutput
On exit: the coefficients ai of the minimax polynomial, for i=0,1,,m.
6:     ref double *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:     fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

Error Indicators and Warnings

Dynamic memory allocation failed.
See Section in How to Use the NAG Library and its Documentation for further information.
On entry, argument value had an illegal value.
On entry, m=value.
Constraint: m<100.
On entry, m=value.
Constraint: m0.
On entry, n=value.
Constraint: n1.
On entry, m=value and n=value.
Constraint: m<n-1.
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 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 2.7.5 in How to Use the NAG Library and its Documentation for further information.
On entry, i=value, x[i]=value and x[i-1]=value.
Constraint: x[i]>x[i-1].


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

nag_1d_minimax_polynomial (e02alc) 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 function. 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 (e02alce.c)

Program Data

Program Data (e02alce.d)

Program Results

Program Results (e02alce.r)