Documentation |
Lambert W function
The Lambert W function W(x) is a set of solutions of the equation x = W(x)e^{W(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*e^{W}:
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
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]
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 the two main branches, and , of the Lambert W function.
Plot the principal branch :
syms x
ezplot(lambertw(x))
Add the branch :
hold on
ezplot(lambertw(-1, x))
Adjust the axes limits and add the title:
axis([-0.5, 4, -4, 2])
title('Lambert W function, two main branches')
[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.