# NAG Library Routine Document

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine e02acf ( x, y, n, a, m1, ref)
 Integer, Intent (In) :: n, m1 Real (Kind=nag_wp), Intent (In) :: x(n), y(n) Real (Kind=nag_wp), Intent (Out) :: a(m1), ref
#include nagmk26.h
 void e02acf_ (const double x[], const double y[], const Integer *n, double a[], const Integer *m1, double *ref)

## 3Description

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).

## 4References

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{x}\left({\mathbf{n}}\right)$ – 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:     $\mathbf{y}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: the values of the $y$ coordinates, ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
3:     $\mathbf{n}$ – IntegerInput
On entry: the number $n$ of data points.
4:     $\mathbf{a}\left({\mathbf{m1}}\right)$ – 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:     $\mathbf{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:     $\mathbf{ref}$ – Real (Kind=nag_wp)Output
On exit: the final reference deviation (see Section 6).

## 6Error Indicators and Warnings

If an error is detected in an input argument e02acf will act as if a soft noisy exit has been requested (see Section 3.4.4 in How to Use the NAG Library and its Documentation).

## 7Accuracy

This is wholly dependent on the given data points.

## 8Parallelism and Performance

e02acf 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 (e02acfe.f90)

None.

### 10.3Program Results

Program Results (e02acfe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017