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_kelvin_ker_vector (s19aq)

Purpose

nag_specfun_kelvin_ker_vector (s19aq) returns an array of values for the Kelvin function kerxkerx.

Syntax

[f, ivalid, ifail] = s19aq(x, 'n', n)
[f, ivalid, ifail] = nag_specfun_kelvin_ker_vector(x, 'n', n)

Description

nag_specfun_kelvin_ker_vector (s19aq) evaluates an approximation to the Kelvin function kerxikerxi for an array of arguments xixi, for i = 1,2,,ni=1,2,,n.
Note:  for x < 0x<0 the function is undefined and at x = 0x=0 it is infinite so we need only consider x > 0x>0.
The function is based on several Chebyshev expansions:
For 0 < x10<x1,
kerx = f(t)log(x) + π/16x2g(t) + y(t)
kerx=-f(t)log(x)+π16x2g(t)+y(t)
where f(t)f(t), g(t)g(t) and y(t)y(t) are expansions in the variable t = 2x41t=2x4-1.
For 1 < x31<x3,
kerx = exp((11/16)x) q(t)
kerx=exp(-1116x) q(t)
where q(t)q(t) is an expansion in the variable t = x2t=x-2.
For x > 3x>3,
kerx = sqrt(π/(2x))ex / sqrt(2) [(1 + 1/xc(t))cosβ1/xd(t)sinβ]
kerx=π 2x e-x/2 [ (1+1xc(t)) cosβ-1xd(t)sinβ]
where β = x/(sqrt(2)) + π/8 β= x2+ π8 , and c(t)c(t) and d(t)d(t) are expansions in the variable t = 6/x1t= 6x-1.
When xx is sufficiently close to zero, the result is computed as
kerx = γlog(x/2) + (π(3/8)x2) (x2)/16
kerx=-γ-log(x2)+(π-38x2) x216
and when xx is even closer to zero, simply as kerx = γlog(x/2) kerx=-γ-log( x2) .
For large xx, kerxkerx is asymptotically given by sqrt(π/(2x))ex / sqrt(2) π 2x e-x/2 and this becomes so small that it cannot be computed without underflow and the function fails.

References

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

Parameters

Compulsory Input Parameters

1:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n0n0.
The argument xixi of the function, for i = 1,2,,ni=1,2,,n.
Constraint: x(i) > 0.0xi>0.0, for i = 1,2,,ni=1,2,,n.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array x.
nn, the number of points.
Constraint: n0n0.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     f(n) – double array
kerxikerxi, the function values.
2:     ivalid(n) – int64int32nag_int array
ivalid(i)ivalidi contains the error code for xixi, for i = 1,2,,ni=1,2,,n.
ivalid(i) = 0ivalidi=0
No error.
ivalid(i) = 1ivalidi=1
xixi is too large, the result underflows. f(i)fi contains zero. The threshold value is the same as for ifail = 1ifail=1 in nag_specfun_kelvin_ker (s19ac), as defined in the Users' Note for your implementation.
ivalid(i) = 2ivalidi=2
xi0.0xi0.0, the function is undefined. f(i)fi contains 0.00.0.
3:     ifail – int64int32nag_int scalar
ifail = 0ifail=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 = 1ifail=1
On entry, at least one value of x was invalid.
Check ivalid for more information.
  ifail = 2ifail=2
Constraint: n0n0.

Accuracy

Let EE be the absolute error in the result, εε be the relative error in the result and δδ be the relative error in the argument. If δδ is somewhat larger than the machine precision, then we have:
E |x/(sqrt(2))(ker1x + kei1x)|δ,
E | x2 ( ker1x+ kei1x ) |δ,
ε |x/(sqrt(2))( ker1x + kei1x )/(kerx)| δ.
ε | x2 ker1x + kei1x kerx | δ.
For very small xx, the relative error amplification factor is approximately given by 1/(|log(x)|) 1|log(x)| , which implies a strong attenuation of relative error. However, εε in general cannot be less than the machine precision.
For small xx, errors are damped by the function and hence are limited by the machine precision.
For medium and large xx, the error behaviour, like the function itself, is oscillatory, and hence only the absolute accuracy for the function can be maintained. For this range of xx, the amplitude of the absolute error decays like sqrt((πx)/2)ex / sqrt(2) πx2e-x/2 which implies a strong attenuation of error. Eventually, kerxkerx, which asymptotically behaves like sqrt(π/(2x))ex / sqrt(2) π2x e-x/2, becomes so small that it cannot be calculated without causing underflow, and the function returns zero. Note that for large xx the errors are dominated by those of the standard function exp.

Further Comments

Underflow may occur for a few values of xx close to the zeros of kerxkerx, below the limit which causes a failure with ifail = 1ifail=1.

Example

function nag_specfun_kelvin_ker_vector_example
x = [0.1; 1; 2.5; 5; 10; 15];
[f, ivalid, ifail] = nag_specfun_kelvin_ker_vector(x);
fprintf('\n    X           Y\n');
for i=1:numel(x)
  fprintf('%12.3e%12.3e%5d\n', x(i), f(i), ivalid(i));
end
 

    X           Y
   1.000e-01   2.420e+00    0
   1.000e+00   2.867e-01    0
   2.500e+00  -6.969e-02    0
   5.000e+00  -1.151e-02    0
   1.000e+01   1.295e-04    0
   1.500e+01  -1.514e-08    0

function s19aq_example
x = [0.1; 1; 2.5; 5; 10; 15];
[f, ivalid, ifail] = s19aq(x);
fprintf('\n    X           Y\n');
for i=1:numel(x)
  fprintf('%12.3e%12.3e%5d\n', x(i), f(i), ivalid(i));
end
 

    X           Y
   1.000e-01   2.420e+00    0
   1.000e+00   2.867e-01    0
   2.500e+00  -6.969e-02    0
   5.000e+00  -1.151e-02    0
   1.000e+01   1.295e-04    0
   1.500e+01  -1.514e-08    0


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–2013