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_cosh (s10ac)

## Purpose

nag_specfun_cosh (s10ac) returns the value of the hyperbolic cosine, $\mathrm{cosh}x$, via the function name.

## Syntax

[result, ifail] = s10ac(x)
[result, ifail] = nag_specfun_cosh(x)

## Description

nag_specfun_cosh (s10ac) calculates an approximate value for the hyperbolic cosine, $\mathrm{cosh}x$.
For $\left|x\right|\le {E}_{1}\text{, }\mathrm{cosh}x=\frac{1}{2}\left({e}^{x}+{e}^{-x}\right)$.
For $\left|x\right|>{E}_{1}$, the function fails owing to danger of setting overflow in calculating ${e}^{x}$. The result returned for such calls is $\mathrm{cosh}{E}_{1}$, i.e., it returns the result for the nearest valid argument.

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

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:

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

W  ${\mathbf{ifail}}=1$
The function has been called with an argument too large in absolute magnitude. There is a danger of overflow. The result returned is the value of $\mathrm{cosh}x$ at the nearest valid argument.
${\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 $\delta$ and $\epsilon$ are the relative errors in the argument and result, respectively, then in principle
 $ε≃xtanh⁡x×δ.$
That is, the relative error in the argument, $x$, is amplified by a factor, at least $x\mathrm{tanh}x$. The equality should hold if $\delta$ is greater than the machine precision ($\delta$ is due to data errors etc.) but if $\delta$ is simply a result of round-off in the machine representation of $x$ then it is possible that an extra figure may be lost in internal calculation round-off.
The behaviour of the error amplification factor is shown by the following graph:
Figure 1
It should be noted that near $x=0$ where this amplification factor tends to zero the accuracy will be limited eventually by the machine precision. Also for $\left|x\right|\ge 2$
 $ε∼xδ=Δ$
where $\Delta$ is the absolute error in the argument $x$.

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 s10ac_example

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

x = [-10   -0.5     0    0.5     25];
n = size(x,2);
result = x;

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

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

```
```s10ac example results

x        cosh(x)
-1.000e+01   1.101e+04
-5.000e-01   1.128e+00
0.000e+00   1.000e+00
5.000e-01   1.128e+00
2.500e+01   3.600e+10
```