NAG CL Interface
c05bbc (lambertw_​complex)

Settings help

CL Name Style:


1 Purpose

c05bbc computes the values of Lambert's W function W(z).

2 Specification

#include <nag.h>
void  c05bbc (Integer branch, Nag_Boolean offset, Complex z, Complex *w, double *resid, NagError *fail)
The function may be called by the names: c05bbc, nag_roots_lambertw_complex or nag_lambertw_complex.

3 Description

c05bbc calculates an approximate value for Lambert's W function (sometimes known as the ‘product log’ or ‘Omega’ function), which is the inverse function of
f(w) = wew   for   wC .  
The function f is many-to-one, and so, except at 0, W is multivalued. c05bbc allows you to specify the branch of W on which you would like the results to lie by using the argument branch. Our choice of branch cuts is as in Corless et al. (1996), and the ranges of the branches of W are summarised in Figure 1.
GnuplotProduced by GNUPLOT 5.4 patchlevel 6 −3p −2p -p 0 π 2p 3p −10 −5 0 5 10 Branch −3 Branch −2 Branch −1 Principal Branch / Branch 0 Branch 1 Branch 2 Branch 3 g(t),t 0.45*t - 5.5, 0 0.1*t-10, -3*pi 0.1*t+10, -3*pi 0.1*t-10, -2*pi 0.1*t+10, -2*pi 0.1*t-10, -pi 0.1*t+10, -pi 0.1*t-10, pi 0.1*t+10, pi 0.1*t-10, 2*pi 0.1*t+10, 2*pi 0.1*t-10, 3*pi 0.1*t+10, 3*pi
Figure 1: Ranges of the branches of W(z)
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 π.
The precise method used to approximate W is as described in Corless et al. (1996). For z close to -exp(−1) greater accuracy comes from evaluating W(-exp(−1)+Δz) rather than W(z): by setting offset=Nag_TRUE on entry you inform c05bbc that you are providing Δz, not z, in z.

4 References

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

5 Arguments

1: branch Integer Input
On entry: the branch required.
2: offset Nag_Boolean Input
On entry: controls whether or not z is being specified as an offset from -exp(−1).
3: z Complex Input
On entry: if offset=Nag_TRUE, z is the offset Δz from -exp(−1) of the intended argument to W; that is, W(β) is computed, where β=-exp(−1)+Δz.
If offset=Nag_FALSE, z is the argument z of the function; that is, W(β) is computed, where β=z.
4: w Complex * Output
On exit: the value W(β): see also the description of z.
5: resid double * Output
On exit: the residual |W(β)exp(W(β))-β|: see also the description of z.
6: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NW_REAL
For the given offset z, W is negligibly different from −1: Re(z)=value and Im(z)=value.
z is close to -exp(−1). Enter z as an offset to -exp(−1) for greater accuracy: Re(z)=value and Im(z)=value.
NW_TOO_MANY_ITER
The iterative procedure used internally did not converge in value iterations. Check the value of resid for the accuracy of w.

7 Accuracy

For a high percentage of z, c05bbc is accurate to the number of decimal digits of precision on the host machine (see X02BEC). An extra digit may be lost on some platforms and for a small proportion of z. This depends on the accuracy of the base-10 logarithm on your system.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
c05bbc is not threaded in any implementation.

9 Further Comments

The following figures show the principal branch of W.
GnuplotProduced by GNUPLOT 5.4 patchlevel 6 gnuplot_plot_1 gnuplot_plot_2 −6 −4 −2 0 2 4 6 −6 −4 −2 0 2 4 6 −1 −0.5 0 0.5 1 1.5 2
Figure 2: real(W0(z))
GnuplotProduced by GNUPLOT 5.4 patchlevel 6 gnuplot_plot_1 gnuplot_plot_2 −6 −4 −2 0 2 4 6 −6 −4 −2 0 2 4 6 −2.5 −2 −1.5 −1 −0.5 0 0.5 1 1.5 2 2.5
Figure 3: Im(W0(z))
GnuplotProduced by GNUPLOT 5.4 patchlevel 6 gnuplot_plot_1 gnuplot_plot_2 −6 −4 −2 0 2 4 6 −6 −4 −2 0 2 4 6 0 0.5 1 1.5 2 2.5
Figure 4: abs(W0(z))

10 Example

This example reads from a file the value of the required branch, whether or not the arguments to W are to be considered as offsets to -exp(−1), and the arguments z themselves. It then evaluates the function for these sets of input data z and prints the results.

10.1 Program Text

Program Text (c05bbce.c)

10.2 Program Data

Program Data (c05bbce.d)

10.3 Program Results

Program Results (c05bbce.r)