bundles / scipy 1.17.1 / scipy / special / _lambertw / lambertw
function
scipy.special._lambertw:lambertw
source: /scipy/special/_lambertw.py :6
Signature
def lambertw ( z , k = 0 , tol = 1e-08 ) Summary
Lambert W function.
Extended Summary
The Lambert W function W(z) is defined as the inverse function of w * exp(w). In other words, the value of W(z) is such that z = W(z) * exp(W(z)) for any complex number z.
The Lambert W function is a multivalued function with infinitely many branches. Each branch gives a separate solution of the equation z = w exp(w). Here, the branches are indexed by the integer k.
Parameters
z: array_likeInput argument.
k: int, optionalBranch index.
tol: float, optionalEvaluation tolerance.
Returns
w: arrayw will have the same shape as
z.
Notes
All branches are supported by lambertw:
lambertw(z)gives the principal solution (branch 0)lambertw(z, k)gives the solution on branchk
The Lambert W function has two partially real branches: the principal branch (k = 0) is real for real z > -1/e, and the k = -1 branch is real for -1/e < z < 0. All branches except k = 0 have a logarithmic singularity at z = 0.
Possible issues
The evaluation can become inaccurate very close to the branch point at -1/e. In some corner cases, lambertw might currently fail to converge, or can end up on the wrong branch.
Algorithm
Halley's iteration is used to invert w * exp(w), using a first-order asymptotic approximation (O(log(w)) or O(w)) as the initial estimate.
The definition, implementation and choice of branches is based on [2].
Examples
The Lambert W function is the inverse of ``w exp(w)``:import numpy as np from scipy.special import lambertw w = lambertw(1)✓
w w * np.exp(w)✗
w = lambertw(1, k=3)
✓w w*np.exp(w)✗
a = 3 b = 2 c = -0.5✓
x = a - lambertw(-b*c*np.exp(a*c))/c
✓x
✗a + b*np.exp(c*x)
✗def tower(z, n): if n == 0: return z return z ** tower(z, n-1) tower(0.5, 100)✓
-lambertw(-np.log(0.5)) / np.log(0.5)
✗See also
- wrightomega
the Wright Omega function
Aliases
-
scipy.special.lambertw