# NAG Library Routine Document

## 1Purpose

e01abf interpolates a function of one variable at a given point $x$ from a table of function values evaluated at equidistant points, using Everett's formula.

## 2Specification

Fortran Interface
 Subroutine e01abf ( n, p, a, g, n1, n2,
 Integer, Intent (In) :: n, n1, n2 Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: p Real (Kind=nag_wp), Intent (Inout) :: a(n1) Real (Kind=nag_wp), Intent (Out) :: g(n2)
#include nagmk26.h
 void e01abf_ ( const Integer *n, const double *p, double a[], double g[], const Integer *n1, const Integer *n2, Integer *ifail)

## 3Description

e01abf interpolates a function of one variable at a given point
 $x=x0+ph,$
where $-1\le p\le 1$ and $h$ is the interval of differencing, from a table of values ${x}_{m}={x}_{0}+mh$ and ${y}_{m}$ where $m=-\left(n-1\right),-\left(n-2\right),\dots ,-1,0,1,\dots ,n$. The formula used is that of Fröberg (1970), neglecting the remainder term:
 $yp=∑r=0 n-1 1-p+r 2r+1 δ2ry0+∑r=0 n-1 p+r 2r+1 δ2ry1.$
The values of ${\delta }^{2r}{y}_{0}$ and ${\delta }^{2r}{y}_{1}$ are stored on exit from the routine in addition to the interpolated function value ${y}_{p}$.

## 4References

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

## 5Arguments

1:     $\mathbf{n}$ – IntegerInput
On entry: $n$, half the number of points to be used in the interpolation.
Constraint: ${\mathbf{n}}>0$.
2:     $\mathbf{p}$ – Real (Kind=nag_wp)Input
On entry: the point $p$ at which the interpolated function value is required, i.e., $p=\left(x-{x}_{0}\right)/h$ with $-1.0.
Constraint: $-1.0\le {\mathbf{p}}\le 1.0$.
3:     $\mathbf{a}\left({\mathbf{n1}}\right)$ – Real (Kind=nag_wp) arrayInput/Output
On entry: ${\mathbf{a}}\left(\mathit{i}\right)$ must be set to the function value ${y}_{\mathit{i}-n}$, for $\mathit{i}=1,2,\dots ,2n$.
On exit: the contents of a are unspecified.
4:     $\mathbf{g}\left({\mathbf{n2}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: the array contains
 $\phantom{{\delta }^{2r}}{y}_{0}$ in ${\mathbf{g}}\left(1\right)$ $\phantom{{\delta }^{2r}}{y}_{1}$ in ${\mathbf{g}}\left(2\right)$ ${\delta }^{2r}{y}_{0}$ in ${\mathbf{g}}\left(2r+1\right)$ ${\delta }^{2r}{y}_{1}$ in ${\mathbf{g}}\left(2\mathit{r}+2\right)$, for $\mathit{r}=1,2,\dots ,n-1$.
The interpolated function value ${y}_{p}$ is stored in ${\mathbf{g}}\left(2n+1\right)$.
5:     $\mathbf{n1}$ – IntegerInput
On entry: the value $2n$, that is, n1 is equal to the number of data points.
6:     $\mathbf{n2}$ – IntegerInput
On entry: the value $2n+1$, that is, n2 is one more than the number of data points.
7:     $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value $-\mathbf{1}\text{​ 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{p}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{p}}\le 1.0$.
On entry, ${\mathbf{p}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{p}}\ge -1.0$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}>0$.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

In general, increasing $n$ improves the accuracy of the result until full attainable accuracy is reached, after which it might deteriorate. If $x$ lies in the central interval of the data (i.e., $0.0\le p<1.0$), as is desirable, an upper bound on the contribution of the highest order differences (which is usually an upper bound on the error of the result) is given approximately in terms of the elements of the array g by $a×\left(\left|{\mathbf{g}}\left(2n-1\right)\right|+\left|{\mathbf{g}}\left(2n\right)\right|\right)$, where $a=0.1$, $0.02$, $0.005$, $0.001$, $0.0002$ for $n=1,2,3,4,5$ respectively, thereafter decreasing roughly by a factor of $4$ each time.
Note that if ${\mathbf{p}}=1$, ${y}_{1}$ is returned. If ${\mathbf{p}}=-1$ and ${\mathbf{n}}>1$, ${y}_{-1}$ is returned. In these cases, no interpolation is necessary and there is no loss of accuracy.

## 8Parallelism and Performance

e01abf is not threaded in any implementation.

The computation time increases as the order of $n$ increases.

## 10Example

This example interpolates at the point $x=0.28$ from the function values
 $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 .$
We take $n=3$ and $p=0.56$.

### 10.1Program Text

Program Text (e01abfe.f90)

### 10.2Program Data

Program Data (e01abfe.d)

### 10.3Program Results

Program Results (e01abfe.r)

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