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_cos (s13ac)


    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example


nag_specfun_integral_cos (s13ac) returns the value of the cosine integral
Cix=γ+lnx+0xcosu-1udu,  x>0  
via the function name where γ denotes Euler's constant.


[result, ifail] = s13ac(x)
[result, ifail] = nag_specfun_integral_cos(x)


nag_specfun_integral_cos (s13ac) calculates an approximate value for Cix.
For 0<x16 it is based on the Chebyshev expansion
Cix=lnx+r=0arTrt,t=2 x16 2-1.  
For 16<x<xhi,
where fx=r=0frTrt and gx=r=0grTrt, t=2 16x 2-1.
For xxhi, Cix=0 to within the accuracy possible (see Accuracy).


Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications


Compulsory Input Parameters

1:     x – double scalar
The argument x of the function.
Constraint: x>0.0.

Optional Input Parameters


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:
The function has been called with an argument less than or equal to zero for which the function is not defined. The result returned is zero.
An unexpected error has been triggered by this routine. Please contact NAG.
Your licence key may have expired or may not have been installed correctly.
Dynamic memory allocation failed.


If E and ε are the absolute and relative errors in the result and δ is the relative error in the argument then in principle these are related by
E δ cosx and ​ ε δ cosx Cix .  
That is accuracy will be limited by machine precision near the origin and near the zeros of cosx, but near the zeros of Cix only absolute accuracy can be maintained.
The behaviour of this amplification is shown in Figure 1.
Figure 1
Figure 1
For large values of x, Cix sinxx  therefore εδxcotx and since δ is limited by the finite precision of the machine it becomes impossible to return results which have any relative accuracy. That is, when x1/δ we have that Cix1/xE and hence is not significantly different from zero.
Hence xhi is chosen such that for values of xxhi, Cix in principle would have values less than the machine precision and so is essentially zero.

Further Comments



This example reads values of the argument x from a file, evaluates the function at each value of x and prints the results.
function s13ac_example

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

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

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

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


function s13ac_plot
  x = [0.1:0.1:2.9,3:0.5:26];
  for j=1:numel(x)
    [ci(j), ifail] = s13ac(x(j));

  fig1 = figure;
  title('Cosine Integral Ci(x)');
  axis([0 26 -1.5 1]);
s13ac example results

      x          Ci(x)
   2.000e-01  -1.042e+00
   4.000e-01  -3.788e-01
   6.000e-01  -2.227e-02
   8.000e-01   1.983e-01
   1.000e+00   3.374e-01

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