Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_fit_withdraw_1dmmax (e02ac)

## Purpose

nag_fit_1dmmax (e02ac) calculates a minimax polynomial fit to a set of data points.

## Syntax

[a, ref] = e02ac(x, y, m1, 'n', n)
[a, ref] = nag_fit_withdraw_1dmmax(x, y, m1, 'n', n)

## Description

Given a set of data points $\left({x}_{i},{y}_{i}\right)$, for $\mathit{i}=1,2,\dots ,n$, nag_fit_1dmmax (e02ac) 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 function also returns a number whose absolute value is the final reference deviation (see Error Indicators and Warnings). The function is an adaptation of Boothroyd (1967).

## 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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{x}\left({\mathbf{n}}\right)$ – double array
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:     $\mathrm{y}\left({\mathbf{n}}\right)$ – double array
The values of the $y$ coordinates, ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
3:     $\mathrm{m1}$int64int32nag_int scalar
$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)$.

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the dimension of the arrays x, y. (An error is raised if these dimensions are not equal.)
The number $n$ of data points.

### Output Parameters

1:     $\mathrm{a}\left({\mathbf{m1}}\right)$ – double array
The coefficients ${a}_{\mathit{i}}$ of the final polynomial, for $\mathit{i}=1,2,\dots ,m+1$.
2:     $\mathrm{ref}$ – double scalar
The final reference deviation (see Error Indicators and Warnings).

## Accuracy

This is wholly dependent on the given data points.

The time taken increases with $m$.

## 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.
```function e02ac_example

fprintf('e02ac example results\n\n');

x = [0:0.05:1]';
y = exp(x);

m1 = int64(6);
[a, ref] = e02ac(x, y, m1);

disp('Polynomial coefficients');
disp(a);
fprintf('\nReference deviation = %10.2e\n\n',ref);

z = x(1:2:end);
pz = polyval(a(end:-1:1),z);
expz = exp(z);
resz = pz - expz;
fprintf('        x     Fit       exp(x) Residual(*10^-6)\n');
disp([z pz expz resz*10^6]);

```
```e02ac example results

Polynomial coefficients
1.0000
1.0001
0.4991
0.1704
0.0348
0.0139

Reference deviation =   1.09e-06

x     Fit       exp(x) Residual(*10^-6)
0    1.0000    1.0000   -1.0915
0.1000    1.1052    1.1052    0.9740
0.2000    1.2214    1.2214   -0.7439
0.3000    1.3499    1.3499   -0.9175
0.4000    1.4918    1.4918    0.2988
0.5000    1.6487    1.6487    1.0915
0.6000    1.8221    1.8221    0.4586
0.7000    2.0138    2.0138   -0.8163
0.8000    2.2255    2.2255   -0.8419
0.9000    2.4596    2.4596    0.8755
1.0000    2.7183    2.7183   -1.0915

```

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015