NAG FL Interface
s13aaf (integral_​exp)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

s13aaf returns the value of the exponential integral E1(x), via the function name.

2 Specification

Fortran Interface
Function s13aaf ( x, ifail)
Real (Kind=nag_wp) :: s13aaf
Integer, Intent (Inout) :: ifail
Real (Kind=nag_wp), Intent (In) :: x
C Header Interface
#include <nag.h>
double  s13aaf_ (const double *x, Integer *ifail)
The routine may be called by the names s13aaf or nagf_specfun_integral_exp.

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 E1 (0) is infinite, and so, when x=0 , s13aaf exits with an error and returns the largest representable machine number.
For 0<x4,
E1(x)=y(t)-lnx=rarTr(t)-lnx,  
where t=12x-1.
For x>4,
E1(x)=e-xxy(t)=e-xxrarTr(t),  
where t=-1.0+14.5 (x+3.25) =11.25-x 3.25+x .
In both cases, -1t+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 x0-0.372507, which corresponds to a simple zero of Ei(-x).
s13aaf guards against producing underflows and overflows by using the argument xhi , see the Users' Note for your implementation for the value of xhi . To guard against overflow, if x<- xhi the routine terminates and returns the negative of the largest representable machine number. To guard against underflow, if x>xhi the result is set directly to zero.

4 References

NIST Digital Library of Mathematical Functions
Cody W J and Thatcher Jr. H C (1969) Rational Chebyshev approximations for the exponential integral Ei(x) Math. Comp. 23 289–303

5 Arguments

1: x Real (Kind=nag_wp) Input
On entry: the argument x of the function.
Constraint: -xhix<0.0 or x>0.0.
2: 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 -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry 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:
ifail=1
On entry, x=0.0 and the function is infinite.
ifail=2
On entry, x=value and the constant xhi=value. The evaluation has been abandoned due to the likelihood of overflow.
Constraint: x-xhi.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
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.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

Unless stated otherwise, it is assumed that x>0.
If δ and ε 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/E1(x). The equality should hold if δ is greater than the machine precision (δ due to data errors etc.) but if δ 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 s13aaf1_fig
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.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
s13aaf is not threaded in any implementation.

9 Further Comments

None.

10 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.

10.1 Program Text

Program Text (s13aafe.f90)

10.2 Program Data

Program Data (s13aafe.d)

10.3 Program Results

Program Results (s13aafe.r)
GnuplotProduced by GNUPLOT 5.4 patchlevel 6 −50 −40 −30 −20 −10 0 10 20 30 40 −5 −4 −3 −2 −1 0 1 2 3 4 5 E1(x) x "s13aafe.r" Example Program Returned Values for the Exponential Integral E1(x)