c05 Chapter Contents
c05 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_lambertW_complex (c05bbc)

## 1  Purpose

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

## 2  Specification

 #include #include
 void nag_lambertW_complex (Integer branch, Nag_Boolean offset, Complex z, Complex *w, double *resid, NagError *fail)

## 3  Description

nag_lambertW_complex (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
 $fw = wew for w∈C .$
The function $f$ is many-to-one, and so, except at $0$, $W$ is multivalued. nag_lambertW_complex (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 summarized in Figure 1.
Figure 1: Ranges of the branches of $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$ is as described in Corless et al. (1996). For $z$ close to $-\mathrm{exp}\left(-1\right)$ greater accuracy comes from evaluating $W\left(-\mathrm{exp}\left(-1\right)+\Delta z\right)$ rather than $W\left(z\right)$: by setting ${\mathbf{offset}}=\mathrm{Nag_TRUE}$ on entry you inform nag_lambertW_complex (c05bbc) that you are providing $\Delta 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:     branchIntegerInput
On entry: the branch required.
2:     offsetNag_BooleanInput
On entry: controls whether or not z is being specified as an offset from $-\mathrm{exp}\left(-1\right)$.
3:     zComplexInput
On entry: if ${\mathbf{offset}}=\mathrm{Nag_TRUE}$, z is the offset $\Delta z$ from $-\mathrm{exp}\left(-1\right)$ of the intended argument to $W$; that is, $W\left(\beta \right)$ is computed, where $\beta =-\mathrm{exp}\left(-1\right)+\Delta z$.
If ${\mathbf{offset}}=\mathrm{Nag_FALSE}$, z is the argument $z$ of the function; that is, $W\left(\beta \right)$ is computed, where $\beta =z$.
4:     wComplex *Output
On exit: the value $W\left(\beta \right)$: see also the description of z.
5:     residdouble *Output
On exit: the residual $\left|W\left(\beta \right)\mathrm{exp}\left(W\left(\beta \right)\right)-\beta \right|$: see also the description of z.
6:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

On entry, argument $〈\mathit{\text{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.
NW_REAL
For the given offset ${\mathbf{z}}$, $W$ is negligibly different from $-1$: $\mathrm{Re}\left({\mathbf{z}}\right)=〈\mathit{\text{value}}〉$ and $\mathrm{Im}\left({\mathbf{z}}\right)=〈\mathit{\text{value}}〉$.
${\mathbf{z}}$ is close to $-\mathrm{exp}\left(-1\right)$. Enter ${\mathbf{z}}$ as an offset to $-\mathrm{exp}\left(-1\right)$ for greater accuracy: $\mathrm{Re}\left({\mathbf{z}}\right)=〈\mathit{\text{value}}〉$ and $\mathrm{Im}\left({\mathbf{z}}\right)=〈\mathit{\text{value}}〉$.
NW_TOO_MANY_ITER
The iterative procedure used internally did not converge in $〈\mathit{\text{value}}〉$ iterations. Check the value of resid for the accuracy of w.

## 7  Accuracy

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

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

## 9  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 $-\mathrm{exp}\left(-1\right)$, and the arguments ${\mathbf{z}}$ themselves. It then evaluates the function for these sets of input data ${\mathbf{z}}$ and prints the results.

### 9.1  Program Text

Program Text (c05bbce.c)

### 9.2  Program Data

Program Data (c05bbce.d)

### 9.3  Program Results

Program Results (c05bbce.r)