Understanding the Lambert W function calculator — concept and principle
The Lambert W function is the inverse of f(w) = w·eʷ: W(x) is the number w that satisfies w·eʷ = x. This calculator returns the principal branch W₀(x) for any x ≥ −1/e and checks the answer by computing w·eʷ. Lambert W solves equations where the unknown appears both outside and inside an exponential, such as x = a·e^(bx) or xˣ = c. It appears in the analysis of algorithms, diode and transistor circuit equations, population models, combustion and enzyme kinetics.
How it is calculated
The calculator solves f(w) = w·eʷ − x = 0 with Halley's method, a third-order relative of Newton's method:
- wₙ₊₁ = wₙ − f ÷ [eʷ(w + 1) − (w + 2)f ÷ (2w + 2)], with f = wₙe^(wₙ) − x.
- Start: w₀ = 0 if x < 1, otherwise w₀ = ln x.
- Stop when the change is below 10⁻¹⁵ (at most 100 steps).
The input must satisfy x ≥ −1/e ≈ −0.3679; there is no real solution below that.
The principle
The function w·eʷ falls to its minimum −1/e at w = −1 and then rises without bound. For x ≥ −1/e, the equation w·eʷ = x therefore has a solution with w ≥ −1, which is the principal branch W₀. For −1/e < x < 0 a second real solution with w < −1 also exists (branch W₋₁), but this calculator returns W₀ only. Halley's method uses both the first and second derivative of f, so near the solution the number of correct digits roughly triples each step.
Worked example
- Default input: x = 1, so we need w with w·eʷ = 1.
- Start: w₀ = ln 1 = 0.
- Step 1: f = −1, giving w₁ = 0.5.
- Step 2: w₂ = 0.5670520513. Step 3: w₃ = 0.5671432904095.
- One more step changes nothing at double precision. Result: W₀(1) = 0.5671432904.
- Check: 0.5671432904 × e^0.5671432904 = 1. This number is known as the omega constant Ω, which also satisfies Ω = e^(−Ω).
| x (≥ −1/e) | W₀(x) |
|---|---|
| 0.25 | 0.2038883547 |
| 0.5 | 0.3517337112 |
| 0.75 | 0.4691502107 |
| 1 | 0.5671432904 |
| 1.25 | 0.6515479054 |
| 1.5 | 0.7258613578 |
| 2 | 0.852605502 |
How to read the result
W₀(0) = 0, W₀(e) = 1 and W₀(−1/e) = −1. For large x, W₀(x) grows slowly, roughly like ln x − ln ln x. The check value should equal your x; a mismatch would signal a convergence problem.
Common mistakes
- Entering x < −1/e, where no real solution exists.
- Forgetting the second branch: for −1/e < x < 0 there are two real solutions, and the physical problem may need W₋₁.
- Rearranging the equation into the wrong form; it must be exactly w·eʷ = (something).
Frequently asked questions
How do I solve xˣ = c with Lambert W?
Take logs: x ln x = ln c. Put u = ln x to get u·eᵘ = ln c, so x = e^(W(ln c)) = ln c ÷ W(ln c).
How do I solve x = a·e^(bx)?
Multiply by −b·e^(−bx) to get (−bx)e^(−bx) = −ab, so x = −W(−ab) ÷ b, real only if −ab ≥ −1/e.
Why is it called Lambert W?
It goes back to work by Johann Heinrich Lambert and Leonhard Euler in the 18th century; the name W was popularised by a 1996 paper by Corless and colleagues.
Sources: Corless, R. M., Gonnet, G. H., Hare, D. E. G., Jeffrey, D. J., Knuth, D. E. (1996), On the Lambert W function, Advances in Computational Mathematics 5, 329–359 · NIST Digital Library of Mathematical Functions, §4.13 Lambert W-Function (dlmf.nist.gov)