Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

# lambertw

Lambert W function

## Description

example

lambertw(x) is the Lambert W function of x. This syntax returns the principal branch of the Lambert W function, and, therefore, it is equivalent to lambertw(0,x).

example

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

## Examples

### Equation Returning the 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
simplify(x - subs(W*exp(W), W, lambertw(k,x))) == 0```
```k =
-2    -1     0     1     2

ans =
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, i)]

Wmin1 =
[             -Inf,              -1]
[ lambertw(-1, pi), lambertw(-1, i)]```

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.576412723*i]

ans =
[                 -Inf,                -1.0]
[ - 0.39097 - 4.6281*i, - 1.0896 - 2.7664*i]```

### Lambert W Function Plot on the 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
ezmeshc(real(lambertw(x + i*y)), [-100, 100, -100, 100])
```

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.

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

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

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

```ezmeshc(abs(lambertw(x + i*y)), [-100, 100, -100, 100])
```

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

```syms x y clear
```

### Plot of the Two Main Branches

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

Plot the principal branch :

```syms x
ezplot(lambertw(x))
```

```hold on
ezplot(lambertw(-1, x))
```

```xlim([-0.5, 4])
ylim([-4, 2])
title('Lambert W function, two main branches')
```

## Input Arguments

expand all

### x — Argument of Lambert W functionnumber | symbolic number | symbolic variable | symbolic expression | symbolic function | vector | matrix

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.

### k — Branch of Lambert W functioninteger | vector | matrix

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.

expand all

### Lambert W Function

The Lambert W function W(x) represents the solutions of the equation x = W(x)eW(x) for any complex number x.

### Tips

• 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 x0, 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.