E02 Chapter Contents
E02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentE02ACF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

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

## 2  Specification

 SUBROUTINE E02ACF ( X, Y, N, A, M1, REF)
 INTEGER N, M1 REAL (KIND=nag_wp) X(N), Y(N), A(M1), REF

## 3  Description

Given a set of data points $\left({x}_{i},{y}_{i}\right)$, for $\mathit{i}=1,2,\dots ,n$, E02ACF uses the exchange algorithm to compute an $m$th-order polynomial
 $Px=a1+a2x+a3x2+⋯+am+1xm$
such that $\underset{i}{\mathrm{max}}\phantom{\rule{0.25em}{0ex}}2\left|\mathrm{P}\left({x}_{i}\right)-{y}_{i}\right|$ is a minimum.
The routine also returns a number whose absolute value is the final reference deviation (see Section 6). 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  Parameters

1:     X(N) – REAL (KIND=nag_wp) arrayInput
On entry: the values of the $x$ coordinates, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
Constraint: ${x}_{1}<{x}_{2}<\cdots <{x}_{n}$.
2:     Y(N) – REAL (KIND=nag_wp) arrayInput
On entry: the values of the $y$ coordinates, ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
3:     N – INTEGERInput
On entry: the number $n$ of data points.
4:     A(M1) – REAL (KIND=nag_wp) arrayOutput
On exit: the coefficients ${a}_{\mathit{i}}$ of the final polynomial, for $\mathit{i}=1,2,\dots ,m+1$.
5:     M1 – INTEGERInput
On entry: $m+1$, where $m$ is the order of the polynomial to be found.
Constraint: ${\mathbf{M1}}<\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{N}},100\right)$.
6:     REF – REAL (KIND=nag_wp)Output
On exit: the final reference deviation (see Section 6).

## 6  Error Indicators and Warnings

If an error is detected in an input parameter E02ACF will act as if a soft noisy exit has been requested (see Section 3.3.4 in the Essential Introduction).

## 7  Accuracy

This is wholly dependent on the given data points.

The time taken increases with $m$.

## 9  Example

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.

### 9.1  Program Text

Program Text (e02acfe.f90)

None.

### 9.3  Program Results

Program Results (e02acfe.r)