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_roots_lambertw_real (c05ba)

Purpose

nag_roots_lambertw_real (c05ba) returns the real values of Lambert's WW function W(x)W(x).

Syntax

[result, ifail] = c05ba(x, branch, offset)
[result, ifail] = nag_roots_lambertw_real(x, branch, offset)

Description

nag_roots_lambertw_real (c05ba) calculates an approximate value for the real branches of Lambert's WW function (sometimes known as the ‘product log’ or ‘Omega’ function), which is the inverse function of
f(w) = wew   for   wC .
f(w) = wew   for   wC .
The function ff is many-to-one, and so, except at 00, WW is multivalued. nag_roots_lambertw_real (c05ba) restricts WW and its argument xx to be real, resulting in a function defined for xexp(1)x-exp(-1) and which is double valued on the interval (exp(1),0)(-exp(-1),0). This double-valued function is split into two real-valued branches according to the sign of W(x) + 1W(x)+1. We denote by W0W0 the branch satisfying W0(x)1W0(x)-1 for all real xx, and by W1W-1 the branch satisfying W1(x)1W-1(x)-1 for all real xx. You may select your branch of interest using the parameter branch.
The precise method used to approximate WW is described fully in Barry et al. (1995). For xx close to exp(1)-exp(-1) greater accuracy comes from evaluating W(exp(1) + Δx)W(-exp(-1)+Δx) rather than W(x)W(x): by setting offset = trueoffset=true on entry you inform nag_roots_lambertw_real (c05ba) that you are providing ΔxΔx, not xx, in x.

References

Barry D J, Culligan–Hensley P J, and Barry S J (1995) Real values of the WW-function ACM Trans. Math. Software 21(2) 161–171

Parameters

Compulsory Input Parameters

1:     x – double scalar
If offset = trueoffset=true, x is the offset ΔxΔx from exp(1)-exp(-1) of the intended argument to WW; that is, W(β)W(β) is computed, where β = exp(1) + Δxβ=-exp(-1)+Δx.
If offset = falseoffset=false, x is the argument xx of the function; that is, W(β)W(β) is computed, where β = xβ=x.
Constraints:
  • if branch = 0branch=0, exp(1)β-exp(-1)β;
  • if branch = 1branch=-1, exp(1)β < 0.0-exp(-1)β<0.0.
2:     branch – int64int32nag_int scalar
The real branch required.
branch = 0branch=0
The branch W0W0 is selected.
branch = 1branch=-1
The branch W1W-1 is selected.
Constraint: branch = 0branch=0 or 1-1.
3:     offset – logical scalar
Controls whether or not x is being specified as an offset from exp(1)-exp(-1).

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     result – double scalar
The result of the function.
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Note: nag_roots_lambertw_real (c05ba) may return useful information for one or more of the following detected errors or 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.

  ifail = 1ifail=1
An input parameter is invalid. .
W ifail = 2ifail=2
Warning: the actual argument to WW was very close to exp(1)-exp(-1).

Accuracy

For a high percentage of legal xx on input, nag_roots_lambertw_real (c05ba) is accurate to the number of decimal digits of precision on the host machine (see nag_machine_decimal_digits (x02be)). An extra digit may be lost on some implementations and for a small proportion of such xx. This depends on the accuracy of the base-1010 logarithm on your system.

Further Comments

None.

Example

function nag_roots_lambertw_real_example
branch = int64(0);
offset = false;
x = [0.5, 1.0, 4.5, 6.0, 7.0e7];
w = zeros(length(x),1);
ifails = zeros(length(x),1);
for i = 1:length(x)
  [w(i), ifails(i)] = nag_roots_lambertw_real(x(i), branch, offset);
end
fprintf('\nBranch = %d\n', branch);
if offset
  fprintf('Offset = true\n\n');
else
  fprintf('Offset = false\n\n');
end
fprintf('      x            w(x)      ifail\n');
for i=1:5
  fprintf('%13.5e %13.5e    %d\n', x(i), w(i), ifails(i));
end
 

Branch = 0
Offset = false

      x            w(x)      ifail
  5.00000e-01   3.51734e-01    0
  1.00000e+00   5.67143e-01    0
  4.50000e+00   1.26724e+00    0
  6.00000e+00   1.43240e+00    0
  7.00000e+07   1.53339e+01    0

function c05ba_example
branch = int64(0);
offset = false;
x = [0.5, 1.0, 4.5, 6.0, 7.0e7];
w = zeros(length(x),1);
ifails = zeros(length(x),1);
for i = 1:length(x)
  [w(i), ifails(i)] = c05ba(x(i), branch, offset);
end
fprintf('\nBranch = %d\n', branch);
if offset
  fprintf('Offset = true\n\n');
else
  fprintf('Offset = false\n\n');
end
fprintf('      x            w(x)      ifail\n');
for i=1:5
  fprintf('%13.5e %13.5e    %d\n', x(i), w(i), ifails(i));
end
 

Branch = 0
Offset = false

      x            w(x)      ifail
  5.00000e-01   3.51734e-01    0
  1.00000e+00   5.67143e-01    0
  4.50000e+00   1.26724e+00    0
  6.00000e+00   1.43240e+00    0
  7.00000e+07   1.53339e+01    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