hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_specfun_integral_exp (s13aa)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_specfun_integral_exp (s13aa) returns the value of the exponential integral E1x, via the function name.

Syntax

[result, ifail] = s13aa(x)
[result, ifail] = nag_specfun_integral_exp(x)

Description

nag_specfun_integral_exp (s13aa) 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 , nag_specfun_integral_exp (s13aa) exits with an error and returns the largest representable machine number.
For 0<x4,
E1x=yt-lnx=rarTrt-lnx,  
where t=12x-1.
For x>4,
E1x=e-xxyt=e-xxrarTrt,  
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).
nag_specfun_integral_exp (s13aa) guards against producing underflows and overflows by using the argument xhi . To guard against overflow, if x<- xhi  the function 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.

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 Eix Math. Comp. 23 289–303

Parameters

Compulsory Input Parameters

1:     x – double scalar
The argument x of the function.
Constraint: -xhix<0.0 or x>0.0.

Optional Input Parameters

None.

Output Parameters

1:     result – double scalar
The result of the function.
2:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

W  ifail=1
On entry, x=0.0 and the function is infinite. The result returned is the largest representable machine number.
   ifail=2
The evaluation has been abandoned due to the likelihood of overflow. The argument x<-xhi , and the result is returned as the negative of the largest representable machine number.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

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/E1x. 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.

Further Comments

None.

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.
function s13aa_example


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

x = [2  -1];
n = size(x,2);
result = x;

for j=1:n
  [result(j), ifail] = s13aa(x(j));
end

disp('      x          E_1(x)');
fprintf('%12.3e%12.3e\n',[x; result]);

s13aa_plot;



function s13aa_plot
  x = [-5:0.1:-0.2, -0.1:0.01:-0.01, -1e-3, -1e-4, -1e-5...
       1e-5, 1e-4, 1e-3, 0.01:0.01:0.1, 0.2:0.1:4.8];
  for j=1:numel(x)
    [e1(j), ifail] = s13aa(x(j));
  end

  fig1 = figure;
  plot(x,e1);
  xlabel('x');
  ylabel('E_1(x)');
  title('Exponential Integral E_1(x)');
s13aa example results

      x          E_1(x)
   2.000e+00   4.890e-02
  -1.000e+00  -1.895e+00
s13aa_fig1.png

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015