Documentation

This is machine translation

Translated by
Mouse over text to see original. Click the button below to return to the English verison of the page.

lambertw

Lambert W function

Syntax

• ``lambertw(x)``
example
• ``lambertw(k,x)``
example

Description

example

````lambertw(x)` is the Lambert W function of `x`, which returns the principal branch of the Lambert W function. Therefore, the syntax is equivalent to `lambertw(0,x)`.```

example

````lambertw(k,x)` is the `k`th branch of the Lambert W function.```

Examples

Equation Returning Lambert W Function as Its Solution

The Lambert W function `W(x)` is a set of solutions of the equation `x = W(x)eW(x)`.

Solve this equation. The solutions is the Lambert W function.

```syms x W solve(x == W*exp(W), W)```
```ans = lambertw(0, x)```

Verify that various branches of the Lambert W function are valid solutions of the equation `x = W*eW`:

```k = -2:2 syms x isAlways(x - subs(W*exp(W), W, lambertw(k,x)) == 0)```
```k = -2 -1 0 1 2 ans = 1×5 logical array 1 1 1 1 1```

Lambert W Function for Numeric and Symbolic Arguments

Depending on its arguments, `lambertw` can return floating-point or exact symbolic results.

Compute the Lambert W functions for these numbers. Because these numbers are not symbolic objects, you get floating-point results.

```A = [0 -1/exp(1); pi i]; lambertw(A) lambertw(-1, A)```
```ans = 0.0000 + 0.0000i -1.0000 + 0.0000i 1.0737 + 0.0000i 0.3747 + 0.5764i ans = -Inf + 0.0000i -1.0000 + 0.0000i -0.3910 - 4.6281i -1.0896 - 2.7664i```

Compute the Lambert W functions for the numbers converted to symbolic objects. For most symbolic (exact) numbers, `lambertw` returns unresolved symbolic calls.

```A = [0 -1/exp(sym(1)); pi i]; W0 = lambertw(A) Wmin1 = lambertw(-1, A)```
```W0 = [ 0, -1] [ lambertw(0, pi), lambertw(0, 1i)] Wmin1 = [ -Inf, -1] [ lambertw(-1, pi), lambertw(-1, 1i)]```

Use `vpa` to approximate symbolic results with the required number of digits:

```vpa(W0, 10) vpa(Wmin1, 5)```
```ans = [ 0, -1.0] [ 1.073658195, 0.3746990207 + 0.576412723i] ans = [ -Inf, -1.0] [ - 0.39097 - 4.6281i, - 1.0896 - 2.7664i]```

Lambert W Function Plot on Complex Plane

Plot the principal branch of the Lambert W function on the complex plane.

Create the combined mesh and contour plot of the real value of the Lambert W function on the complex plane.

```syms x y real fmesh(real(lambertw(x + i*y)), [-100, 100, -100, 100], 'ShowContours', 'on') ```

Now, plot the imaginary value of the Lambert W function on the complex plane. This function has a branch cut along the negative real axis. For better perspective, create the mesh and contour plots separately.

```fmesh(imag(lambertw(x + i*y)), [-100, 100, -100, 100]) ```

```fcontour(imag(lambertw(x + i*y)), [-100, 100, -100, 100], 'Fill', 'on') ```

Plot the absolute value of the Lambert W function on the complex plane.

```fmesh(abs(lambertw(x + i*y)), [-100, 100, -100, 100], 'ShowContours', 'on') ```

For further computations, clear the assumptions on `x` and `y`:

```syms x y clear ```

Plot Two Main Branches

Plot the two main branches, and , of the Lambert W function.

Plot the principal branch . Add the branch . Adjust the axes limits and add the title.

```syms x fplot(lambertw(x)) hold on fplot(lambertw(-1, x)) axis([-0.5, 4, -4, 2]) title('Lambert W function, two main branches') ```

Input Arguments

collapse all

Argument of Lambert W function, specified as a number, symbolic number, variable, expression, function, or vector or matrix of numbers, symbolic numbers, variables, expressions, or functions. If `x` is a vector or matrix, `lambertW` returns the Lambert W function for each element of `x`.

Branch of Lambert W function, specified as an integer or a vector or matrix of integers. If `k` is a vector or matrix, `lambertW` returns the Lambert W function for each element of `k`.

collapse all

Lambert W Function

The Lambert W function W(x) represents the solutions y of the equation $y{e}^{y}=x$ for any complex number `x`.

• For complex x, the equation has an infinite number of solutions y = lambertW(k,x) where k ranges over all integers.

• For real x where x ≥ 0, the equation has exactly one real solution y = lambertW(x) = lambertW(0,x).

• For real x where $-{e}^{-1}, the equation has exactly two real solutions. The larger solution is represented by y = lambertW(x) and the smaller solution by y = lambertW(-1,x).

• For $x=-{e}^{-1}$, the equation has exactly one real solution y = -1 = lambertW(0, -exp(-1)) = lambertW(-1, -exp(-1)).

Algorithms

• The equation `x = w(x)ew(x)` has infinitely many solutions on the complex plane. These solutions are represented by `w = lambertw(k,x)` with the branch index `k` ranging over the integers.

• For all real `x``0`, the equation `x = w(x)ew(x)` has exactly one real solution. It is represented by `w = lambertw(x)` or, equivalently, `w = lambertw(0,x)`.

• For all real `x` in the range ```-1/e < x < 0```, there are exactly two distinct real solutions. The larger one is represented by `w = lambertw(x)`, and the smaller one is represented by `w = lambertw(-1,x)`.

• For `w = -1/e`, there is exactly one real solution ```lambertw(0, -exp(-1)) = lambertw(-1, -exp(-1)) = -1```.

• `lambertw(k,x)` returns real values only if `k = 0` or `k = -1`. For ```k <> {0, -1}```, `lambertw(k,x)` is always complex.

• At least one input argument must be a scalar or both arguments must be vectors or matrices of the same size. If one input argument is a scalar and the other one is a vector or a matrix, `lambertw` expands the scalar into a vector or matrix of the same size as the other argument with all elements equal to that scalar.

References

[1] Corless, R.M, G.H. Gonnet, D.E.G. Hare, D.J. Jeffrey, and D.E. Knuth "On the Lambert W Function" Advances in Computational Mathematics, vol.5, pp. 329–359, 1996.

[2] Corless, R.M, G.H. Gonnet, D.E.G. Hare, and D.J. Jeffrey "Lambert's W Function in Maple" The Maple Technical Newsletter (MapleTech), vol.9, pp. 12–22, 1993.