W {LambertW} | R Documentation |
Lambert W function, its logarithm and derivative
Description
The Lambert W function is defined as the inverse
of (see
xexp
)
i.e., it satisfies .
W
evaluates the Lambert W function (W
), its first derivative
(deriv_W
), and its logarithm (log_W
). All of them have a
principal (branch = 0
(default)) and non-principal branch
(branch = -1
) solution.
W
is a wrapper for lambertW0
and
lambertWm1
in the lamW package.
Usage
W(z, branch = 0)
deriv_W(z, branch = 0, W.z = W(z, branch = branch))
log_deriv_W(z, branch = 0, W.z = W(z, branch = branch))
deriv_log_W(z, branch = 0, W.z = W(z, branch = branch))
log_W(z, branch = 0, W.z = W(z, branch = branch))
Arguments
z |
a numeric vector of real values; note that |
branch |
either |
W.z |
Lambert W function evaluated at |
Details
Depending on the argument of
one can distinguish 3 cases:
solution is unique
W(z) = W(z, branch = 0)
;
two solutions: the principal (
W(z, branch = 0)
) and non-principal (W(z, branch = -1)
) branch;no solution exists in the reals.
log_W
computes the natural logarithm of . This can be done
efficiently since
. Similarly, the
derivative can be expressed as a function of
:
Note that and
.
Moreover, by taking logs on both sides we can even simplify further to
which, since
, simplifies to
For this reason it is numerically faster to pass the value of as
an argument to
deriv_W
since W(z)
often has already been
evaluated in a previous step.
Value
numeric; same dimensions/size as z
.
W
returns numeric, Inf
(for z = Inf
), or NA
if
.
Note that W
handles NaN
differently to
lambertW0
/ lambertWm1
in the lamW package; it returns
NA
.
References
Corless, R. M., G. H. Gonnet, D. E. G. Hare, D. J. Jeffrey and D. E. Knuth (1996). “On the Lambert W function”. Advances in Computational Mathematics, pp. 329-359.
See Also
lambertW0
/ lambertWm1
in the lamW package;
xexp
.
Examples
W(-0.25) # "reasonable" input event
W(-0.25, branch = -1) # "extreme" input event
curve(W(x, branch = -1), -1, 2, type = "l", col = 2, lwd = 2)
curve(W(x), -1, 2, type = "l", add = TRUE, lty = 2)
abline(v = - 1 / exp(1))
# For lower values, the principal branch gives the 'wrong' solution;
# the non-principal must be used.
xexp(-10)
W(xexp(-10), branch = 0)
W(xexp(-10), branch = -1)
curve(log(x), 0.1, 5, lty = 2, col = 1, ylab = "")
curve(W(x), 0, 5, add = TRUE, col = "red")
curve(log_W(x), 0.1, 5, add = TRUE, col = "blue")
grid()
legend("bottomright", c("log(x)", "W(x)", "log(W(x))"),
col = c("black", "red", "blue"), lty = c(2, 1, 1))