E02 Chapter Contents
E02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentE02RAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

E02RAF calculates the coefficients in a Padé approximant to a function from its user-supplied Maclaurin expansion.

## 2  Specification

 SUBROUTINE E02RAF ( IA, IB, C, IC, A, B, W, JW, IFAIL)
 INTEGER IA, IB, IC, JW, IFAIL REAL (KIND=nag_wp) C(IC), A(IA), B(IB), W(JW)

## 3  Description

Given a power series
 $c0+c1x+c2x2+⋯+cl+mxl+m+⋯$
E02RAF uses the coefficients ${c}_{i}$, for $\mathit{i}=0,1,\dots ,l+m$, to form the $\left[l/m\right]$ Padé approximant of the form
 $a0+a1x+a2x2+⋯+alxl b0+b1x+b2x2+⋯+bmxm$
with ${b}_{0}$ defined to be unity. The two sets of coefficients ${a}_{j}$, for $\mathit{j}=0,1,\dots ,l$, and ${b}_{k}$, for $\mathit{k}=0,1,\dots ,m$, in the numerator and denominator are calculated by direct solution of the Padé equations (see Graves–Morris (1979)); these values are returned through the argument list unless the approximant is degenerate.
Padé approximation is a useful technique when values of a function are to be obtained from its Maclaurin expansion but convergence of the series is unacceptably slow or even nonexistent. It is based on the hypothesis of the existence of a sequence of convergent rational approximations, as described in Baker and Graves–Morris (1981) and Graves–Morris (1979).
Unless there are reasons to the contrary (as discussed in Chapter 4, Section 2, Chapters 5 and 6 of Baker and Graves–Morris (1981)), one normally uses the diagonal sequence of Padé approximants, namely
 $m/m,m=0,1,2,….$
Subsequent evaluation of the approximant at a given value of $x$ may be carried out using E02RBF.

## 4  References

Baker G A Jr and Graves–Morris P R (1981) Padé approximants, Part 1: Basic theory encyclopaedia of Mathematics and its Applications Addison–Wesley
Graves–Morris P R (1979) The numerical calculation of Padé approximants Padé Approximation and its Applications. Lecture Notes in Mathematics (ed L Wuytack) 765 231–245 Adison–Wesley

## 5  Parameters

1:     IA – INTEGERInput
2:     IB – INTEGERInput
On entry: IA must specify $l+1$ and IB must specify $m+1$, where $l$ and $m$ are the degrees of the numerator and denominator of the approximant, respectively.
Constraint: ${\mathbf{IA}}\ge 1$ and ${\mathbf{IB}}\ge 1$.
3:     C(IC) – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{C}}\left(\mathit{i}\right)$ must specify, for $\mathit{i}=1,2,\dots ,l+m+1$, the coefficient of ${x}^{\mathit{i}-1}$ in the given power series.
4:     IC – INTEGERInput
On entry: the dimension of the array C as declared in the (sub)program from which E02RAF is called.
Constraint: ${\mathbf{IC}}\ge {\mathbf{IA}}+{\mathbf{IB}}-1$.
5:     A(IA) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{A}}\left(\mathit{j}+1\right)$, for $\mathit{j}=1,2,\dots ,l+1$, contains the coefficient ${a}_{\mathit{j}}$ in the numerator of the approximant.
6:     B(IB) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{B}}\left(\mathit{k}+1\right)$, for $\mathit{k}=1,2,\dots ,m+1$, contains the coefficient ${b}_{\mathit{k}}$ in the denominator of the approximant.
7:     W(JW) – REAL (KIND=nag_wp) arrayWorkspace
8:     JW – INTEGERInput
On entry: the dimension of the array W as declared in the (sub)program from which E02RAF is called.
Constraint: ${\mathbf{JW}}\ge {\mathbf{IB}}×\left(2×{\mathbf{IB}}+3\right)$.
9:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction 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 parameter, 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).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{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{JW}}<{\mathbf{IB}}×\left(2×{\mathbf{IB}}+3\right)$, or ${\mathbf{IA}}<1$, or ${\mathbf{IB}}<1$, or ${\mathbf{IC}}<{\mathbf{IA}}+{\mathbf{IB}}-1$
(so there are insufficient coefficients in the given power series to calculate the desired approximant).
${\mathbf{IFAIL}}=2$

## 7  Accuracy

The solution should be the best possible to the extent to which the solution is determined by the input coefficients. It is recommended that you determine the locations of the zeros of the numerator and denominator polynomials, both to examine compatibility with the analytic structure of the given function and to detect defects. (Defects are nearby pole-zero pairs; defects close to $x=0.0$ characterise ill-conditioning in the construction of the approximant.) Defects occur in regions where the approximation is necessarily inaccurate. The example program calls C02AGF to determine the above zeros.
It is easy to test the stability of the computed numerator and denominator coefficients by making small perturbations of the original Maclaurin series coefficients (e.g., ${c}_{l}$ or ${c}_{l+m}$). These questions of intrinsic error of the approximants and computational error in their calculation are discussed in Chapter 2 of Baker and Graves–Morris (1981).

The time taken is approximately proportional to ${m}^{3}$.

## 9  Example

This example calculates the $\left[4/4\right]$ Padé approximant of ${e}^{x}$ (whose power-series coefficients are first stored in the array C). The poles and zeros are then calculated to check the character of the $\left[4/4\right]$ Padé approximant.

### 9.1  Program Text

Program Text (e02rafe.f90)

None.

### 9.3  Program Results

Program Results (e02rafe.r)