# NAG FL Interfacee02alf (dim1_​minimax_​polynomial)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine e02alf ( n, x, y, m, a, ref,
 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
#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.

## 3Description

Given a set of data points $\left({x}_{i},{y}_{i}\right)$, for $\mathit{i}=1,2,\dots ,n$, e02alf uses the exchange algorithm to compute an $m$th-degree polynomial
 $P(x) = a0 + a1x + a2 x2 + ⋯ + am xm$
such that $\underset{i}{\mathrm{max}}\phantom{\rule{0.25em}{0ex}}|\mathrm{P}\left({x}_{i}\right)-{y}_{i}|$ 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

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the number of data points.
Constraint: ${\mathbf{n}}\ge 1$.
2: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the values of the $x$ coordinates, ${x}_{i}$, for $\mathit{i}=1,2,\dots ,n$.
Constraint: ${x}_{1}<{x}_{2}<\cdots <{x}_{n}$.
3: $\mathbf{y}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the values of the $y$ coordinates, ${y}_{i}$, for $\mathit{i}=1,2,\dots ,n$.
4: $\mathbf{m}$Integer Input
On entry: $m$, where $m$ is the degree of the polynomial to be found.
Constraint: $0\le {\mathbf{m}}<\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(100,{\mathbf{n}}-1\right)$.
5: $\mathbf{a}\left({\mathbf{m}}+1\right)$Real (Kind=nag_wp) array Output
On exit: the coefficients ${a}_{i}$ of the minimax polynomial, for $\mathit{i}=0,1,\dots ,m$.
6: $\mathbf{ref}$Real (Kind=nag_wp) Output
On exit: the final reference deviation, i.e., the maximum deviation of the computed polynomial evaluated at ${x}_{\mathit{i}}$ from the reference values ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$. ref may return a negative value which indicates that the algorithm started to cycle due to round-off errors.
7: $\mathbf{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 $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{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:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 1$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}<100$.
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}\ge 0$.
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}<{\mathbf{n}}-1$.
${\mathbf{ifail}}=3$
On entry, $\mathit{i}=⟨\mathit{\text{value}}⟩$, ${\mathbf{x}}\left(\mathit{i}+1\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{x}}\left(\mathit{i}\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{x}}\left(\mathit{i}+1\right)>{\mathbf{x}}\left(\mathit{i}\right)$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{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.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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 (${\mathbf{n}}>100$, say), rounding error will affect the computation regardless of the quality of the data; in this case, relatively small degree polynomials (${\mathbf{m}}\ll \sqrt{{\mathbf{n}}}$) 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.

## 8Parallelism 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.

The time taken increases with $m$.

## 10Example

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

### 10.1Program Text

Program Text (e02alfe.f90)

### 10.2Program Data

Program Data (e02alfe.d)

### 10.3Program Results

Program Results (e02alfe.r)