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

# NAG Toolbox: nag_specfun_integral_cos (s13ac)

## Purpose

nag_specfun_integral_cos (s13ac) returns the value of the cosine integral
 $Cix=γ+ln⁡x+∫0xcos⁡u-1udu, x>0$
via the function name where $\gamma$ denotes Euler's constant.

## Syntax

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

## Description

nag_specfun_integral_cos (s13ac) calculates an approximate value for $\mathrm{Ci}\left(x\right)$.
For $0 it is based on the Chebyshev expansion
 $Cix=ln⁡x+∑r=0′arTrt,t=2 x16 2-1.$
For $16,
 $Cix=fxsin⁡xx-gxcos⁡xx2$
where $f\left(x\right)=\underset{r=0}{{\sum }^{\prime }}\phantom{\rule{0.25em}{0ex}}{f}_{r}{T}_{r}\left(t\right)$ and $g\left(x\right)=\underset{r=0}{{\sum }^{\prime }}\phantom{\rule{0.25em}{0ex}}{g}_{r}{T}_{r}\left(t\right)$, $t=2{\left(\frac{16}{x}\right)}^{2}-1$.
For $x\ge {x}_{\mathrm{hi}}$, $\mathrm{Ci}\left(x\right)=0$ to within the accuracy possible (see Accuracy).

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{x}$ – double scalar
The argument $x$ of the function.
Constraint: ${\mathbf{x}}>0.0$.

None.

### Output Parameters

1:     $\mathrm{result}$ – double scalar
The result of the function.
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 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.
${\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

If $E$ and $\epsilon$ are the absolute and relative errors in the result and $\delta$ is the relative error in the argument then in principle these are related by
 $E≃ δ cos⁡x and ​ ε≃ δ cos⁡x Cix .$
That is accuracy will be limited by machine precision near the origin and near the zeros of $\mathrm{cos}x$, but near the zeros of $\mathrm{Ci}\left(x\right)$ only absolute accuracy can be maintained.
The behaviour of this amplification is shown in Figure 1.
Figure 1
For large values of $x$, $\mathrm{Ci}\left(x\right)\sim \frac{\mathrm{sin}x}{x}$ therefore $\epsilon \sim \delta x\mathrm{cot}x$ and since $\delta$ is limited by the finite precision of the machine it becomes impossible to return results which have any relative accuracy. That is, when $x\ge 1/\delta$ we have that $\left|\mathrm{Ci}\left(x\right)\right|\le 1/x\sim E$ and hence is not significantly different from zero.
Hence ${x}_{\mathrm{hi}}$ is chosen such that for values of $x\ge {x}_{\mathrm{hi}}$, $\mathrm{Ci}\left(x\right)$ in principle would have values less than the machine precision and so is essentially zero.

None.

## Example

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));
end

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

s13ac_plot;

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));
end

fig1 = figure;
plot(x,ci);
xlabel('x');
ylabel('Ci(x)');
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
```