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

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_interp_1d_aitken (e01aa)

## Purpose

nag_interp_1d_aitken (e01aa) interpolates a function of one variable at a given point $x$ from a table of function values ${y}_{i}$ evaluated at equidistant or non-equidistant points ${x}_{i}$, for $\mathit{i}=1,2,\dots ,n+1$, using Aitken's technique of successive linear interpolations.

## Syntax

[a, b, c] = e01aa(a, b, n, x)
[a, b, c] = nag_interp_1d_aitken(a, b, n, x)
Note: the interface to this routine has changed since earlier releases of the toolbox:
 At Mark 23: n1 is no longer an optional input parameter; n2 is no longer an input parameter

## Description

nag_interp_1d_aitken (e01aa) interpolates a function of one variable at a given point $x$ from a table of values ${x}_{i}$ and ${y}_{i}$, for $i=1,2,\dots ,n+1$ using Aitken's method (see Fröberg (1970)). The intermediate values of linear interpolations are stored to enable an estimate of the accuracy of the results to be made.

## References

Fröberg C E (1970) Introduction to Numerical Analysis Addison–Wesley

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{a}\left(\mathit{n1}\right)$ – double array
${\mathbf{a}}\left(\mathit{i}\right)$ must contain the $x$-component of the $\mathit{i}$th data point, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n+1$.
2:     $\mathrm{b}\left(\mathit{n1}\right)$ – double array
${\mathbf{b}}\left(\mathit{i}\right)$ must contain the $y$-component (function value) of the $\mathit{i}$th data point, ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n+1$.
3:     $\mathrm{n}$int64int32nag_int scalar
The number of intervals which are to be used in interpolating the value at $x$; that is, there are $n+1$ data points $\left({x}_{i},{y}_{i}\right)$.
Constraint: ${\mathbf{n}}>0$.
4:     $\mathrm{x}$ – double scalar
The point $x$ at which the interpolation is required.

None.

### Output Parameters

1:     $\mathrm{a}\left(\mathit{n1}\right)$ – double array
$\mathit{n1}={\mathbf{n}}+1$.
${\mathbf{a}}\left(\mathit{i}\right)$ contains the value ${x}_{\mathit{i}}-x$, for $\mathit{i}=1,2,\dots ,n+1$.
2:     $\mathrm{b}\left(\mathit{n1}\right)$ – double array
$\mathit{n1}={\mathbf{n}}+1$.
The contents of b are unspecified.
3:     $\mathrm{c}\left(\mathit{n2}\right)$ – double array
$\mathit{n2}={\mathbf{n}}×\left({\mathbf{n}}+1\right)/2$.
• ${\mathbf{c}}\left(1\right),\dots ,{\mathbf{c}}\left(n\right)$ contain the first set of linear interpolations,
• ${\mathbf{c}}\left(n+1\right),\dots ,{\mathbf{c}}\left(2×n-1\right)$ contain the second set of linear interpolations,
• ${\mathbf{c}}\left(2n\right),\dots ,{\mathbf{c}}\left(3×n-3\right)$ contain the third set of linear interpolations,
• $⋮$
• ${\mathbf{c}}\left(n×\left(n+1\right)/2\right)$ contains the interpolated function value at the point $x$.

None.

## Accuracy

An estimate of the accuracy of the result can be made from a comparison of the final result and the previous interpolates, given in the array c. In particular, the first interpolate in the $i$th set, for $i=1,2,\dots ,n$, is the value at $x$ of the polynomial interpolating the first $\left(i+1\right)$ data points. It is given in position $\left(i-1\right)\left(2n-i+2\right)/2$ of the array c. Ideally, providing $n$ is large enough, this set of $n$ interpolates should exhibit convergence to the final value, the difference between one interpolate and the next settling down to a roughly constant magnitude (but with varying sign). This magnitude indicates the size of the error (any subsequent increase meaning that the value of $n$ is too high). Better convergence will be obtained if the data points are supplied, not in their natural order, but ordered so that the first $i$ data points give good coverage of the neighbourhood of $x$, for all $i$. To this end, the following ordering is recommended as widely suitable: first the point nearest to $x$, then the nearest point on the opposite side of $x$, followed by the remaining points in increasing order of their distance from $x$, that is of $\left|{x}_{r}-x\right|$. With this modification the Aitken method will generally perform better than the related method of Neville, which is often given in the literature as superior to that of Aitken.

The computation time for interpolation at any point $x$ is proportional to $n×\left(n+1\right)/2$.

## Example

This example interpolates at $x=0.28$ the function value of a curve defined by the points
 $xi -1.00 -0.50 0.00 0.50 1.00 1.50 yi 0.00 -0.53 -1.00 -0.46 2.00 11.09 .$
```function e01aa_example

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

a = [-1  -0.50   0    0.50    1    1.50];
b = [ 0  -0.53  -1   -0.46    2   11.09];
n = int64(5);

x = 0.28;
[ax, bx, c] = e01aa(a, b, n, x);

k = 1;

disp('Interpolated values');
for i = n-1:-1:1
fprintf('%12.5f',c(k:k+i));
fprintf('\n');
k = k + i + 1;
end

fprintf('\nInterpolation point = %12.5f\n', x);
fprintf('\nFunction value at interpolation point = %12.5f\n', c(end));

```
```e01aa example results

Interpolated values
-1.35680    -1.28000    -0.39253     1.28000     5.67808
-1.23699    -0.60467     0.01434     1.38680
-0.88289    -0.88662    -0.74722
-0.88125    -0.91274

Interpolation point =      0.28000

Function value at interpolation point =     -0.83591
```