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_kei_vector (s19ar)

Purpose

nag_specfun_kelvin_kei_vector (s19ar) returns an array of values for the Kelvin function keixkeix.

Syntax

[f, ivalid, ifail] = s19ar(x, 'n', n)
[f, ivalid, ifail] = nag_specfun_kelvin_kei_vector(x, 'n', n)

Description

nag_specfun_kelvin_kei_vector (s19ar) evaluates an approximation to the Kelvin function keixikeixi for an array of arguments xixi, for i = 1,2,,ni=1,2,,n.
Note:  for x < 0x<0 the function is undefined, so we need only consider x0x0.
The function is based on several Chebyshev expansions:
For 0x10x1,
keix = π/4f(t) + (x2)/4[g(t)log(x) + v(t)]
keix=-π4f(t)+x24[-g(t)log(x)+v(t)]
where f(t)f(t), g(t)g(t) and v(t)v(t) are expansions in the variable t = 2x41t=2x4-1;
For 1 < x31<x3,
keix = exp((9/8)x) u(t)
keix=exp(-98x) u(t)
where u(t)u(t) is an expansion in the variable t = x2t=x-2;
For x > 3x>3,
keix = sqrt(π/(2x))ex / sqrt(2) [(1 + 1/x)c(t)sinβ + 1/xd(t)cosβ]
keix=π 2x e-x/2 [ (1+1x) c(t)sinβ+1xd(t)cosβ]
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.
For x < 0x<0, the function is undefined, and hence the function fails and returns zero.
When xx is sufficiently close to zero, the result is computed as
keix = π/4 + (1γlog(x/2)) (x2)/4
keix=-π4+(1-γ-log(x2) ) x24
and when xx is even closer to zero simply as
keix = π/4.
keix=-π4.
For large xx, keixkeix 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.0xi0.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
keixikeixi, 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_kei (s19ad), as defined in the Users' Note for your implementation.
ivalid(i) = 2ivalidi=2
xi < 0.0xi<0.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, and δδ be the relative error in the argument. If δδ is somewhat larger than the machine representation error, then we have:
E |x/(sqrt(2))(ker1x + kei1x)|δ.
E | x2 ( - ker1x+ kei1x ) |δ.
For small xx, errors are attenuated 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 absolute accuracy of 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, keixkeix, which is asymptotically given by sqrt(π/(2x))ex / sqrt(2) π2x e-x/2, becomes so small that it cannot be calculated without causing underflow and therefore 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 keixkeix, below the limit which causes a failure with ifail = 1ifail=1.

Example

function nag_specfun_kelvin_kei_vector_example
x = [0; 0.1; 1; 2.5; 5; 10; 15];
[f, ivalid, ifail] = nag_specfun_kelvin_kei_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
   0.000e+00  -7.854e-01    0
   1.000e-01  -7.769e-01    0
   1.000e+00  -4.950e-01    0
   2.500e+00  -1.107e-01    0
   5.000e+00   1.119e-02    0
   1.000e+01  -3.075e-04    0
   1.500e+01   7.963e-06    0

function s19ar_example
x = [0; 0.1; 1; 2.5; 5; 10; 15];
[f, ivalid, ifail] = s19ar(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
   0.000e+00  -7.854e-01    0
   1.000e-01  -7.769e-01    0
   1.000e+00  -4.950e-01    0
   2.500e+00  -1.107e-01    0
   5.000e+00   1.119e-02    0
   1.000e+01  -3.075e-04    0
   1.500e+01   7.963e-06    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