Lambert W function - MATLAB lambertw (2024)

Lambert W function

collapse all in page

Syntax

lambertw(x)

lambertw(k,x)

Description

example

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

example

lambertw(k,x) is the kth branch of the Lambert W function. This syntax returns real values only if k = 0 or k = -1.

Examples

collapse all

Return Equation with Lambert W Function as Its Solution

The Lambert W function W(x) isa set of solutions of the equation x = W(x)eW(x).

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

syms x Weqn = x == W*exp(W);solve(eqn,W)
ans =lambertw(0, x)

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

k = -2:2;eqn = subs(eqn,W,lambertw(k,x));isAlways(eqn)
ans = 1×5 logical array 1 1 1 1 1

Lambert W Function for Numeric and Symbolic Arguments

Depending on its arguments, lambertw canreturn floating-point or exact symbolic results.

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

A = [0 -1/exp(1); pi i];lambertw(A)
ans = 0.0000 + 0.0000i -1.0000 + 0.0000i 1.0737 + 0.0000i 0.3747 + 0.5764i
lambertw(-1,A)
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)
W0 =[ 0, -1][ lambertw(0, pi), lambertw(0, 1i)]
Wmin1 = lambertw(-1,A)
Wmin1 =[ -Inf, -1][ lambertw(-1, pi), lambertw(-1, 1i)]

Convert symbolic results to double by using double.

double(W0)
ans = 0.0000 + 0.0000i -1.0000 + 0.0000i 1.0737 + 0.0000i 0.3747 + 0.5764i

Plot Two Main Branches of Lambert W Function

Open Live Script

Plot the two main branches, W0(x) and W-1(x), of the Lambert W function.

syms xfplot(lambertw(x))hold onfplot(lambertw(-1,x))hold offaxis([-0.5 4 -4 2])title('Lambert W function, two main branches')legend('k=0','k=1','Location','best')

Lambert W function - MATLAB lambertw (1)

Lambert W Function Plot on Complex Plane

Open Live Script

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

Plot the real value of the Lambert W function by using fmesh. Simultaneously plot the contours by setting 'ShowContours' to 'On'.

syms x yf = lambertw(x + 1i*y);interval = [-100 100 -100 100];fmesh(real(f),interval,'ShowContours','On')

Lambert W function - MATLAB lambertw (2)

Plot the imaginary value of the Lambert W function. The plot has a branch cut along the negative real axis. Plot the contours separately.

fmesh(imag(f),interval)

Lambert W function - MATLAB lambertw (3)

fcontour(imag(f),interval,'Fill','on')

Lambert W function - MATLAB lambertw (4)

Plot the absolute value of the Lambert W function.

fmesh(abs(f),interval,'ShowContours','On')

Lambert W function - MATLAB lambertw (5)

Input Arguments

collapse all

xInput
number | vector | matrix | array | symbolic number | symbolic variable | symbolic array | symbolic function | symbolic expression

Input, specified as a number, vector, matrix, or array, or a symbolic number, variable, array, function, or expression.

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 is a vector or 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.

kBranch of Lambert W function
integer | vector or matrix of integers | symbolic integer | symbolic vector or matrix of integers

Branch of Lambert W function, specified as an integer, a vector or matrix of integers, a symbolic integer, or a symbolic vector or matrix of integers.

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 is a vector or 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.

More About

collapse all

Lambert W Function

The Lambert W function W(x) representsthe solutions y of the equation yey=x for any complex number x.

  • For complex x, the equation hasan infinite number of solutions y = lambertW(k,x) where k rangesover all integers.

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

  • For real x where e1<x<0, 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=e1, the equation has exactly one real solution y = –1 = lambertW(0, –exp(–1)) = lambertW(–1, -exp(–1)).

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.

Version History

Introduced before R2006a

See Also

Functions

  • wrightOmega

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Lambert W function - MATLAB lambertw (6)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Lambert W function - MATLAB lambertw (2024)

FAQs

What is the Lambert W function equal to? ›

In mathematics, the Lambert W function, also called the omega function or product logarithm, is a multivalued function, namely the branches of the converse relation of the function f(w) = wew, where w is any complex number and ew is the exponential function.

What is the generalized Lambert W function? ›

The Lambert W function gives the solutions of a simple exponential polynomial. The generalized Lambert W function was defined by Mezö and Baricz, and has found applications in delay differential equations and physics.

What is the principal branch of the Lambert function? ›

The branch corresponding to k = 0 is the principal branch. In mathematical notation, the k is usually a subscript, i.e W0(z) is the principal branch of the Lambert W function. For real z ≥ -1/e it returns a real value.

How does the solve function work in MATLAB? ›

S = solve( eqn , var ) solves the equation eqn for the variable var . If you do not specify var , the symvar function determines the variable to solve for. For example, solve(x + 1 == 2, x) solves the equation x + 1 = 2 for x.

How to calculate transfer function using MATLAB? ›

Create the transfer function G ( s ) = s s 2 + 3 s + 2 : num = [1 0]; den = [1 3 2]; G = tf(num,den); num and den are the numerator and denominator polynomial coefficients in descending powers of s. For example, den = [1 3 2] represents the denominator polynomial s2 + 3s + 2.

How is the Lambert W function computed? ›

The Lambert W function W(z) is the inverse function of f(w) = wew, meaning that W(z)eW(z) = z holds for any z.

What is the Lambert W function in engineering? ›

The Lambert W function, although not familiar to many engi- late 1700s. W(z) is the function that solves the equation As stated in [2], even if z is real, the branches other than p = 0 and p-1 are always complex. where, in general, z is a complex number.

What is the representation of the Lambert W function? ›

The Lambert W function is the many-valued analytic inverse of z(w)=we w . We use elementary complex analysis to derive closed-form representations of all of the branches of W through simple quadratures.

Is the Lambert W function analytic? ›

The Lambert W function is defined as the multivalued inverse of the function w↦wew. It has a wide range of applications. We propose a new method to construct a high-precision analytical approximation of the two branches of W. The method is based on Padé approximation and Schröder's iteration.

What is the inverse of the Lambert W function? ›

The inverse of this function is called the Lambert W_{-1} function. It is represented by its maroon graph in the picture below. Mathematica's notation for W_0(x) function is ProductLog[x], or, equivalently ProductLog[0,x]. Mathematica's notation for W_{-1}(x) function is ProductLog[-1,x].

What is the real branch of the Lambert W function? ›

Figure 1 Real branches of the Lambert W function. The solid line is the principal branch W0; the dashed line is W−1, which is the only other branch that takes real values. The small filled circle at the branch point corresponds to the one in figure 2. The Wright ω function helps to solve the equation y +ln y = z.

What is the formula for the Lambert function? ›

The Lambert W function is known in mathematics as the inverse of f(x)=xex f ( x ) = x e x ; y=xex⇔x=W(y) y = x e x ⇔ x = W ( y ) . The following alternative definition is often used to solve Equations of type of y=f(x)^e^f(x):

What is the principal function? ›

The basic idea of principal functions is simple: Given a Riemann surface or a Riemannian space R, a neighborhood A of its ideal boundary, and a harmonic function s on A, the principal function problem consists in constructing a harmonic function p on all of R which imitates the behavior of s in A.

How to use theta function in MATLAB? ›

Th = THETA(TYPE,V,M) returns values of theta functions evaluated for corresponding values of argument V and parameter M. TYPE is a type of the theta function, there are four numbered types. The arrays V and M must be the same size (or either can be scalar).

How to do a Taylor approximation in MATLAB? ›

T = taylor( f , var ) approximates f with the Taylor series expansion of f up to the fifth order at the point var = 0 . If you do not specify var , then taylor uses the default variable determined by symvar(f,1) . T = taylor( f , var , a ) approximates f with the Taylor series expansion of f at the point var = a .

How can I use function in MATLAB? ›

Syntax for Function Definition
  1. function myOutput = myFunction(x) If your function returns more than one output, enclose the output names in square brackets.
  2. function [one,two,three] = myFunction(x) If there is no output, you can omit it.
  3. function myFunction(x) Or you can use empty square brackets.

How to do square function in MATLAB? ›

x = square( t ) generates a square wave with period 2π for the elements of the time array t . square is similar to the sine function but creates a square wave with values of –1 and 1. x = square( t , duty ) generates a square wave with specified duty cycle duty .

Top Articles
Latest Posts
Article information

Author: Prof. Nancy Dach

Last Updated:

Views: 5593

Rating: 4.7 / 5 (57 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Prof. Nancy Dach

Birthday: 1993-08-23

Address: 569 Waelchi Ports, South Blainebury, LA 11589

Phone: +9958996486049

Job: Sales Manager

Hobby: Web surfing, Scuba diving, Mountaineering, Writing, Sailing, Dance, Blacksmithing

Introduction: My name is Prof. Nancy Dach, I am a lively, joyous, courageous, lovely, tender, charming, open person who loves writing and wants to share my knowledge and understanding with you.