# NAG FL Interfacee01raf (dim1_​ratnl)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

e01raf produces, from a set of function values and corresponding abscissae, the coefficients of an interpolating rational function expressed in continued fraction form.

## 2Specification

Fortran Interface
 Subroutine e01raf ( n, x, f, m, a, u, iw,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: m, iw(n) Real (Kind=nag_wp), Intent (In) :: x(n), f(n) Real (Kind=nag_wp), Intent (Out) :: a(n), u(n)
#include <nag.h>
 void e01raf_ (const Integer *n, const double x[], const double f[], Integer *m, double a[], double u[], Integer iw[], Integer *ifail)
The routine may be called by the names e01raf or nagf_interp_dim1_ratnl.

## 3Description

e01raf produces the parameters of a rational function $R\left(x\right)$ which assumes prescribed values ${f}_{i}$ at prescribed values ${x}_{i}$ of the independent variable $x$, for $\mathit{i}=1,2,\dots ,n$. More specifically, e01raf determines the parameters ${a}_{j}$, for $\mathit{j}=1,2,\dots ,m$ and ${u}_{j}$, for $\mathit{j}=1,2,\dots ,m-1$, in the continued fraction
 $R(x)=a1+Rm(x)$ (1)
where
 $Ri(x)=am-i+ 2(x-um-i+ 1) 1+Ri- 1(x) , for ​ i=m,m- 1,…,2,$
and
 $R1(x)=0,$
such that $R\left({x}_{i}\right)={f}_{i}$, for $\mathit{i}=1,2,\dots ,n$. The value of $m$ in (1) is determined by the routine; normally $m=n$. The values of ${u}_{j}$ form a reordered subset of the values of ${x}_{i}$ and their ordering is designed to ensure that a representation of the form (1) is determined whenever one exists.
The subsequent evaluation of (1) for given values of $x$ can be carried out using e01rbf.
The computational method employed in e01raf is the modification of the Thacher–Tukey algorithm described in Graves–Morris and Hopkins (1981).

## 4References

Graves–Morris P R and Hopkins T R (1981) Reliable rational interpolation Numer. Math. 36 111–128

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the number of data points.
Constraint: ${\mathbf{n}}>0$.
2: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: ${\mathbf{x}}\left(\mathit{i}\right)$ must be set to the value of the $\mathit{i}$th data abscissa, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
Constraint: the ${\mathbf{x}}\left(i\right)$ must be distinct.
3: $\mathbf{f}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: ${\mathbf{f}}\left(\mathit{i}\right)$ must be set to the value of the data ordinate, ${f}_{\mathit{i}}$, corresponding to ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
4: $\mathbf{m}$Integer Output
On exit: $m$, the number of terms in the continued fraction representation of $R\left(x\right)$.
5: $\mathbf{a}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: ${\mathbf{a}}\left(\mathit{j}\right)$ contains the value of the parameter ${a}_{\mathit{j}}$ in $R\left(x\right)$, for $\mathit{j}=1,2,\dots ,m$. The remaining elements of a, if any, are set to zero.
6: $\mathbf{u}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: ${\mathbf{u}}\left(\mathit{j}\right)$ contains the value of the parameter ${u}_{\mathit{j}}$ in $R\left(x\right)$, for $\mathit{j}=1,2,\dots ,m-1$. The ${u}_{j}$ are a permuted subset of the elements of x. The remaining $n-m+1$ locations contain a permutation of the remaining ${x}_{i}$, which can be ignored.
7: $\mathbf{iw}\left({\mathbf{n}}\right)$Integer array Workspace
8: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}>0$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{x}}\left(\mathit{I}\right)$ is very close to ${\mathbf{x}}\left(\mathit{J}\right)$: $\mathit{I}=⟨\mathit{\text{value}}⟩$, ${\mathbf{x}}\left(\mathit{I}\right)=⟨\mathit{\text{value}}⟩$, $\mathit{J}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{x}}\left(\mathit{J}\right)=⟨\mathit{\text{value}}⟩$.
${\mathbf{ifail}}=3$
A continued fraction of the required form does not exist.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

Usually, it is not the accuracy of the coefficients produced by this routine which is of prime interest, but rather the accuracy of the value of $R\left(x\right)$ that is produced by the associated routine e01rbf when subsequently it evaluates the continued fraction (1) for a given value of $x$. This final accuracy will depend mainly on the nature of the interpolation being performed. If interpolation of a ‘well-behaved smooth’ function is attempted (and provided the data adequately represents the function), high accuracy will normally ensue, but, if the function is not so ‘smooth’ or extrapolation is being attempted, high accuracy is much less likely. Indeed, in extreme cases, results can be highly inaccurate.
There is no built-in test of accuracy but several courses are open to you to prevent the production or the acceptance of inaccurate results.
1. 1.If the origin of a variable is well outside the range of its data values, the origin should be shifted to correct this; and, if the new data values are still excessively large or small, scaling to make the largest value of the order of unity is recommended. Thus, normalization to the range $-1.0$ to $+1.0$ is ideal. This applies particularly to the independent variable; for the dependent variable, the removal of leading figures which are common to all the data values will usually suffice.
2. 2.To check the effect of rounding errors engendered in the routines themselves, e01raf should be re-entered with ${x}_{1}$ interchanged with ${x}_{i}$ and ${f}_{1}$ with ${f}_{i}$, $\left(i\ne 1\right)$. This will produce a completely different vector $a$ and a reordered vector $u$, but any change in the value of $R\left(x\right)$ subsequently produced by e01rbf will be due solely to rounding error.
3. 3.Even if the data consist of calculated values of a formal mathematical function, it is only in exceptional circumstances that bounds for the interpolation error (the difference between the true value of the function underlying the data and the value which would be produced by the two routines if exact arithmetic were used) can be derived that are sufficiently precise to be of practical use. Consequently, you are recommended to rely on comparison checks: if extra data points are available, the calculation may be repeated with one or more data pairs added or exchanged, or alternatively, one of the original data pairs may be omitted. If the algorithms are being used for extrapolation, the calculations should be performed repeatedly with the $2,3,\dots \text{}$ nearest points until, hopefully, successive values of $R\left(x\right)$ for the given $x$ agree to the required accuracy.

## 8Parallelism and Performance

e01raf is not threaded in any implementation.

The time taken by e01raf is approximately proportional to ${n}^{2}$.
The continued fraction (1) when expanded produces a rational function in $x$, the degree of whose numerator is either equal to or exceeds by unity that of the denominator. Only if this rather special form of interpolatory rational function is needed explicitly, would this routine be used without subsequent entry (or entries) to e01rbf.

## 10Example

This example reads in the abscissae and ordinates of $5$ data points and prints the arguments ${a}_{j}$ and ${u}_{j}$ of a rational function which interpolates them.

### 10.1Program Text

Program Text (e01rafe.f90)

### 10.2Program Data

Program Data (e01rafe.d)

### 10.3Program Results

Program Results (e01rafe.r)