S Chapter Contents
S Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentS13AAF

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.
Warning. The specification of the parameter X changed at Mark 21: ${\mathbf{X}}<0.0$ is no longer regarded as an input error.

## 1  Purpose

S13AAF returns the value of the exponential integral ${E}_{1}\left(x\right)$, via the function name.

## 2  Specification

 FUNCTION S13AAF ( X, IFAIL)
 REAL (KIND=nag_wp) S13AAF
 INTEGER IFAIL REAL (KIND=nag_wp) X

## 3  Description

S13AAF calculates an approximate value for
 $E1 x = -Ei -x = ∫x∞ e-u u du .$
using Chebyshev expansions, where $x$ is real. For $x<0$, the real part of the principal value of the integral is taken. The value ${E}_{1}\left(0\right)$ is infinite, and so, when $x=0$, S13AAF exits with an error and returns the largest representable machine number.
For $0,
 $E1x=yt-ln⁡x=∑′rarTrt-ln⁡x,$
where $t=\frac{1}{2}x-1$.
For $x>4$,
 $E1x=e-xxyt=e-xx∑′rarTrt,$
where $t=-1.0+\frac{14.5}{\left(x+3.25\right)}=\frac{11.25-x}{3.25+x}$.
In both cases, $-1\le t\le +1$.
For $x<0$, the approximation is based on expansions proposed by Cody and Thatcher Jr. (1969). Precautions are taken to maintain good relative accuracy in the vicinity of ${x}_{0}\approx -0.372507\dots \text{}$, which corresponds to a simple zero of Ei($-x$).
S13AAF guards against producing underflows and overflows by using the parameter ${x}_{\mathrm{hi}}$; see the Users' Note for your implementation for the value of ${x}_{\mathrm{hi}}$. To guard against overflow, if $x<-{x}_{\mathrm{hi}}$ the routine terminates and returns the negative of the largest representable machine number. To guard against underflow, if $x>{x}_{\mathrm{hi}}$ the result is set directly to zero.

## 4  References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Cody W J and Thatcher Jr. H C (1969) Rational Chebyshev approximations for the exponential integral Ei$\left(x\right)$ Math. Comp. 23 289–303

## 5  Parameters

1:     X – REAL (KIND=nag_wp)Input
On entry: the argument $x$ of the function.
Constraint: $-{x}_{\mathrm{hi}}\le {\mathbf{X}}<0.0$ or ${\mathbf{X}}>0.0$.
2:     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{X}}=0.0$ and the function is infinite. The result returned is the largest representable machine number.
${\mathbf{IFAIL}}=2$
The evaluation has been abandoned due to the likelihood of overflow. The argument ${\mathbf{X}}<-{x}_{\mathrm{hi}}$, and the result is returned as the negative of the largest representable machine number.

## 7  Accuracy

Unless stated otherwise, it is assumed that $x>0$.
If $\delta$ and $\epsilon$ are the relative errors in argument and result respectively, then in principle,
 $ε≃ e-x E1 x ×δ$
so the relative error in the argument is amplified in the result by at least a factor ${e}^{-x}/{E}_{1}\left(x\right)$. The equality should hold if $\delta$ is greater than the machine precision ($\delta$ due to data errors etc.) but if $\delta$ is simply a result of round-off in the machine representation, it is possible that an extra figure may be lost in internal calculation and round-off.
The behaviour of this amplification factor is shown in the following graph:
Figure 1
It should be noted that, for absolutely small $x$, the amplification factor tends to zero and eventually the error in the result will be limited by machine precision.
For absolutely large $x$,
 $ε∼xδ=Δ,$
the absolute error in the argument.
For $x<0$, empirical tests have shown that the maximum relative error is a loss of approximately $1$ decimal place.

None.

## 9  Example

The following program reads values of the argument $x$ from a file, evaluates the function at each value of $x$ and prints the results.

### 9.1  Program Text

Program Text (s13aafe.f90)

### 9.2  Program Data

Program Data (s13aafe.d)

### 9.3  Program Results

Program Results (s13aafe.r)