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

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_specfun_cosh (s10ac) returns the value of the hyperbolic cosine, coshx, 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, coshx.
For xE1,  coshx=12ex+e-x.
For x>E1, the function fails owing to danger of setting overflow in calculating ex. The result returned for such calls is coshE1, 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:     x – double scalar
The argument x of the function.

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
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 coshx at the nearest valid argument.
   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

If δ and ε are the relative errors in the argument and result, respectively, then in principle
εxtanhx×δ.  
That is, the relative error in the argument, x, is amplified by a factor, at least xtanhx. The equality should hold if δ is greater than the machine precision (δ is due to data errors etc.) but if δ 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:
GnuplotProduced by GNUPLOT 4.6 patchlevel 3 0 2 4 6 8 10 −10 −5 0 5 10 ε/δ x gnuplot_plot_1
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 x2 
εxδ=Δ  
where Δ is the absolute error in the argument x.

Further Comments

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

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