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

## Purpose

nag_fit_pade_eval (e02rb) evaluates a rational function at a user-supplied point, given the numerator and denominator coefficients.

## Syntax

[ans, ifail] = e02rb(a, b, x, 'ia', ia, 'ib', ib)
[ans, ifail] = nag_fit_pade_eval(a, b, x, 'ia', ia, 'ib', ib)

## Description

Given a real value $x$ and the coefficients ${a}_{j}$, for $\mathit{j}=0,1,\dots ,l$ and ${b}_{k}$, for $\mathit{k}=0,1,\dots ,m$, nag_fit_pade_eval (e02rb) evaluates the rational function
 $∑j=0lajxj ∑k=0mbkxk .$
using nested multiplication (see Conte and de Boor (1965)).
A particular use of nag_fit_pade_eval (e02rb) is to compute values of the Padé approximants determined by nag_fit_pade_app (e02ra).

## References

Conte S D and de Boor C (1965) Elementary Numerical Analysis McGraw–Hill
Peters G and Wilkinson J H (1971) Practical problems arising in the solution of polynomial equations J. Inst. Maths. Applics. 8 16–35

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{a}\left({\mathbf{ia}}\right)$ – double array
${\mathbf{a}}\left(\mathit{j}+1\right)$, for $\mathit{j}=1,2,\dots ,l+1$, must contain the value of the coefficient ${a}_{\mathit{j}}$ in the numerator of the rational function.
2:     $\mathrm{b}\left({\mathbf{ib}}\right)$ – double array
${\mathbf{b}}\left(\mathit{k}+1\right)$, for $\mathit{k}=1,2,\dots ,m+1$, must contain the value of the coefficient ${b}_{k}$ in the denominator of the rational function.
Constraint: if ${\mathbf{ib}}=1$, ${\mathbf{b}}\left(1\right)\ne 0.0$.
3:     $\mathrm{x}$ – double scalar
The point $x$ at which the rational function is to be evaluated.

### Optional Input Parameters

1:     $\mathrm{ia}$int64int32nag_int scalar
Default: the dimension of the array a.
The value of $l+1$, where $l$ is the degree of the numerator.
Constraint: ${\mathbf{ia}}\ge 1$.
2:     $\mathrm{ib}$int64int32nag_int scalar
Default: the dimension of the array b.
The value of $m+1$, where $m$ is the degree of the denominator.
Constraint: ${\mathbf{ib}}\ge 1$.

### Output Parameters

1:     $\mathrm{ans}$ – double scalar
The result of evaluating the rational function at the given point $x$.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
The rational function is being evaluated at or near a pole.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{ia}}<1$, or ${\mathbf{ib}}<1$, or ${\mathbf{b}}\left(1\right)=0.0$ when ${\mathbf{ib}}=1$ (so the denominator is identically zero).
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

A running error analysis for polynomial evaluation by nested multiplication using the recurrence suggested by Kahan (see Peters and Wilkinson (1971)) is used to detect whether you are attempting to evaluate the approximant at or near a pole.

The time taken is approximately proportional to $l+m$.

## Example

This example first calls nag_fit_pade_app (e02ra) to calculate the $4/4$ Padé approximant to ${e}^{x}$, and then uses nag_fit_pade_eval (e02rb) to evaluate the approximant at $x=0.1,0.2,\dots ,1.0$.
```function e02rb_example

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

ia = int64(5);
ib = int64(5);
ic = ia + ib - 1;
c  = ones(ic,1);
for j = 3:ic
c(j) = c(j-1)/double(j-1);
end

[a, b, ifail] = e02ra(ia, ib, c);

for j=1:30
x = j/10;
[padx, ifail] = e02rb(a, b, x);
expx = exp(x);
err(j) = relerr;
if (mod(j,3)==1)
end
end

x = [0.1:0.1:3];
fig1 = figure;
hold on;
plot(x,f,'s',x,log10(err),'o');
plot(x,exp(x),'Color','Magenta');
title('The [4|4] Pade approximant of exp(x)');
xlabel('x');
hold off;

```
```e02rb example results

0.1     1.10517     1.10517     0.00e+00
0.4     1.49182     1.49182     1.04e-11
0.7     2.01375     2.01375     1.61e-09
1.0     2.71828     2.71828     4.05e-08
1.3     3.66930     3.66930     4.39e-07
1.6     4.95302     4.95303     2.91e-06
1.9     6.68580     6.68589     1.41e-05
2.2     9.02452     9.02501     5.47e-05
2.5    12.18030    12.18249     1.80e-04
2.8    16.43608    16.44465     5.21e-04
```