NAG CL Interface
e02alc (dim1_​minimax_​polynomial)

Settings help

CL Name Style:


1 Purpose

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

2 Specification

#include <nag.h>
void  e02alc (Integer n, const double x[], const double y[], Integer m, double a[], double *ref, NagError *fail)
The function may be called by the names: e02alc, nag_fit_dim1_minimax_polynomial or nag_1d_minimax_polynomial.

3 Description

Given a set of data points (xi,yi), for i=1,2,,n, e02alc 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 function also returns a number whose absolute value is the final reference deviation (see Section 5). The function 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] const double Input
On entry: the values of the x coordinates, xi, for i=1,2,,n.
Constraint: x1<x2<<xn.
3: y[n] const double 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] double Output
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 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT
On entry, m=value.
Constraint: m<100.
On entry, m=value.
Constraint: m0.
On entry, n=value.
Constraint: n1.
NE_INT_2
On entry, m=value and n=value.
Constraint: m<n-1.
NE_INTERNAL_ERROR
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 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_NOT_STRICTLY_INCREASING
On entry, i=value, x[i]=value and x[i-1]=value.
Constraint: x[i]>x[i-1].

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

Background information to multithreading can be found in the Multithreading documentation.
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.

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

10.2 Program Data

Program Data (e02alce.d)

10.3 Program Results

Program Results (e02alce.r)