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_roots_lambertw_complex (c05bb)

## Purpose

nag_roots_lambertw_complex (c05bb) computes the values of Lambert's W$W$ function W(z)$W\left(z\right)$.

## Syntax

[w, resid, ifail] = c05bb(branch, offset, z)
[w, resid, ifail] = nag_roots_lambertw_complex(branch, offset, z)

## Description

nag_roots_lambertw_complex (c05bb) calculates an approximate value for Lambert's W$W$ function (sometimes known as the ‘product log’ or ‘Omega’ function), which is the inverse function of
 f(w) = wew   for   w ∈ C . $f(w) = wew for w∈C .$
The function f$f$ is many-to-one, and so, except at 0$0$, W$W$ is multivalued. nag_roots_lambertw_complex (c05bb) allows you to specify the branch of W$W$ on which you would like the results to lie by using the parameter branch. Our choice of branch cuts is as in Corless et al. (1996), and the ranges of the branches of W$W$ are summarised in Figure 1.
Figure 1: Ranges of the branches of W(z)$W\left(z\right)$
For more information about the closure of each branch, which is not displayed in Figure 1, see Corless et al. (1996). The dotted lines in the Figure denote the asymptotic boundaries of the branches, at multiples of π$\pi$.
The precise method used to approximate W$W$ is as described in Corless et al. (1996). For z$z$ close to exp(1)$-\mathrm{exp}\left(-1\right)$ greater accuracy comes from evaluating W(exp(1) + Δz)$W\left(-\mathrm{exp}\left(-1\right)+\Delta z\right)$ rather than W(z)$W\left(z\right)$: by setting on entry you inform nag_roots_lambertw_complex (c05bb) that you are providing Δz$\Delta z$, not z$z$, in z.

## References

Corless R M, Gonnet G H, Hare D E G, Jeffrey D J and Knuth D E (1996) On the Lambert W$W$ function Advances in Comp. Math. 3 329–359

## Parameters

### Compulsory Input Parameters

1:     branch – int64int32nag_int scalar
The branch required.
2:     offset – logical scalar
Controls whether or not z is being specified as an offset from exp(1)$-\mathrm{exp}\left(-1\right)$.
3:     z – complex scalar
If , z is the offset Δz$\Delta z$ from exp(1)$-\mathrm{exp}\left(-1\right)$ of the intended argument to W$W$; that is, W(β)$W\left(\beta \right)$ is computed, where β = exp(1) + Δz$\beta =-\mathrm{exp}\left(-1\right)+\Delta z$.
If , z is the argument z$z$ of the function; that is, W(β)$W\left(\beta \right)$ is computed, where β = z$\beta =z$.

None.

None.

### Output Parameters

1:     w – complex scalar
The value W(β)$W\left(\beta \right)$: see also the description of z.
2:     resid – double scalar
The residual |W(β)exp(W(β))β|$|W\left(\beta \right)\mathrm{exp}\left(W\left(\beta \right)\right)-\beta |$: see also the description of z.
3:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Note: nag_roots_lambertw_complex (c05bb) 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.

W ifail = 1${\mathbf{ifail}}=1$
For the given offset z${\mathbf{z}}$, W$W$ is negligibly different from 1$-1$.
z${\mathbf{z}}$ is close to exp(1)$-\mathrm{exp}\left(-1\right)$.
W ifail = 2${\mathbf{ifail}}=2$
The iterative procedure used internally did not converge in _$_$ iterations. Check the value of resid for the accuracy of w.

## Accuracy

For a high percentage of z${\mathbf{z}}$, nag_roots_lambertw_complex (c05bb) 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 platforms and for a small proportion of z${\mathbf{z}}$. This depends on the accuracy of the base-10$10$ logarithm on your system.

The following figures show the principal branch of W$W$.
Figure 2: real(W0(z))$\mathrm{real}\left({W}_{0}\left(z\right)\right)$
Figure 3: Im(W0(z))$\mathrm{Im}\left({W}_{0}\left(z\right)\right)$
Figure 4: abs(W0(z))$\mathrm{abs}\left({W}_{0}\left(z\right)\right)$

## Example

```function nag_roots_lambertw_complex_example
branch = int64(0);
offset = false;
z = [0.5-i; 1+2.3*i; 4.5-0.1*i; 6+6*i];
fprintf('\nBranch = %d\n', branch);
if offset
fprintf('Offset = true\n');
else
fprintf('Offset = false\n');
end
fprintf('\n               z            w           resid    ifail\n');
for j =1:4
[w, resid, ifail] = nag_roots_lambertw_complex(branch, offset, z(j)) ;
fprintf('%18s %18s %10s %3d\n', num2str(z(j)), num2str(w), num2str(resid), ifail);
end
```
```

Branch = 0
Offset = false

z            w           resid    ifail
0.5-1i   0.51651-0.42205i 5.5511e-17   0
1+2.3i   0.87361+0.57698i 1.1102e-16   0
4.5-0.1i   1.2673-0.012419i          0   0
6+6i    1.6149+0.49051i 1.2561e-15   0

```
```function c05bb_example
branch = int64(0);
offset = false;
z = [0.5-i; 1+2.3*i; 4.5-0.1*i; 6+6*i];
fprintf('\nBranch = %d\n', branch);
if offset
fprintf('Offset = true\n');
else
fprintf('Offset = false\n');
end
fprintf('\n               z            w           resid    ifail\n');
for j =1:4
[w, resid, ifail] = c05bb(branch, offset, z(j)) ;
fprintf('%18s %18s %10s %3d\n', num2str(z(j)), num2str(w), num2str(resid), ifail);
end
```
```

Branch = 0
Offset = false

z            w           resid    ifail
0.5-1i   0.51651-0.42205i 5.5511e-17   0
1+2.3i   0.87361+0.57698i 1.1102e-16   0
4.5-0.1i   1.2673-0.012419i          0   0
6+6i    1.6149+0.49051i 1.2561e-15   0

```