Document not found! Please try again

Lambert's W Function in Maple - Semantic Scholar

17 downloads 40 Views 221KB Size Report
Robert M. Corless, 1 Gaston H. Gonnet, 2. D. E. G. Hare, 3 and David J. Je ... Informatik, ETH, Z urich, Switzerland, [email protected]. 3Symbolic Computation ...
Lambert's W Function in Maple Robert M. Corless, 1 Gaston H. Gonnet, 2 D. E. G. Hare, 3 and David J. Je rey 4

De nition and Notation

Many users of Maple have encountered a function called W . The simplest way one might meet this function is shown in the following session fragment. >solve(w*exp(w)=x,w);

W(x)

What is this function, and why is it in Maple? The rst part of that question is already answered by the above Maple session: W (x) is de ned to be `the' solution to the equation wew = x. Actually, for some values of x, this equation has more than one root, in which case the di erent solutions are called branches of W . The way we handle branches is described later. The reason why W is included in Maple is simply that it has appeared in the solution of enough problems to have earned the right to have a name of its own. [For a function, getting your own name is rather like Pinocchio getting to be a real boy.] This article concentrates on the real-valued branches of W and their manipulation in Maple. It is problem-oriented, because we found that the investigation of Lambert's W function was very pleasant, and believe that some of that pleasure is best transmitted by a participatory article | that is, one that leaves some work for the reader. Readers are encouraged to try the problems at the end of the article, using Maple as required. A more detailed paper [4] is available which discusses the complex-valued function W (z ) and its Maple implementation. A PostScript version of [4] can be obtained by anonymous ftp to cs-archive.uwaterloo.ca, from the directory cs-archive/CS-93-03, and also by anonymous ftp to the Maple share library, from the le maple/5.2/doc/LambertW.ps. Notation: The letter W is now a standard notation for this function, following early Maple usage. In [4] we proposed to call this Lambert's W function, because Lambert set the rst problem which required W for its solution, and because Euler attributed the series with which he solved the problem to Lambert. In [3], it is also called the `omega' function, because there is a persistent rumor that there are papers which use the greek letter ! for this function. If any readers of this article can provide a reference for this notation, please inform us by e-mail to [email protected]. If x is real, then for ?1=e  x < 0 there are two possible real values of W (x) (see Figure 1). We denote the branch satisfying ?1  W (x) by W (x), and the branch satisfying W (x)  ?1 by W (x). W (x) is referred to as the principal branch of the W function. This notation is di erent from that used in [4], which agrees with the intended notation for the research version of Maple, whereas the notation of the present article agrees with the implemented notation for 0

Dept. Applied Math, University of Western Ontario, London, Canada, [email protected] Dept. Informatik, ETH, Zurich, Switzerland, [email protected] 3 Symbolic Computation Group, University of Waterloo, Waterloo, Canada, [email protected] 4 Dept. Applied Math, University of Western Ontario, London, Canada, [email protected]

1

2

12

Lambert's W function Maple V Release 2. Finally, we sometimes get sloppy and use W to indicate both real branches, or either branch, or even sometimes a complex branch, whenever this is clear from the context.

W 1 −1/e

x

−1

1

2

3

−1 −2 −3 −4

Figure 1. The two real branches of W (x). ||, W (x); { { {, W (x). 0

Sample Applications

Members of the maple_group electronic mailing list may recall some discussions of the W function. The following problems have been taken from those discussions, plus some other sources. Solution of a Jet Fuel Problem

This problem was contributed to maple_group by Michael Kamprath, with commentary by Harald Hanche-Olsen. Consider the following equations, which describe the endurance Et and range R of a jet airplane. We wish to nd the thrust speci c fuel consumption ct and the weight of the fuel w ? w , given the physical constants describing the plane and its environment. The equations are [1] (p. 312) 0

1

  Et = cCCL log ww t D  2CL  =  =  2 w ?w = ; R = c C S 0

1

1 2

t D

1 2

1 2

0

1

where Et is the endurance, CL and CD are the lift and drag coecients, w is the initial weight of the plane, w is the nal weight of the plane, R is the range, S is the planform area of the 0

1

13

Lambert's W function plane's wings, and  is the ambient air density. We simplify these equations by rst grouping the physical parameters and nondimensionalizing. We put w = w =w and c = Et CD ct =CL , and introduce the new parameter p  = A = ? 2Et w : 1

R

0

0

1 2

SCL

The equations then become c = ? log(w) and pw 1 ? 2A log(w) = 1 : This equation has exactly one real solution if A < 0, since the left-hand side is a strictly increasing function of W . It can be solved in terms of W , the solution being

8 ? > : A? W 2

2

2

2 0





AeA ; if A  ?1





AeA ; if ?1  A < 0

In Maple V Release 2, we get > assume(A solve(2*A*(1-sqrt(w))/log(w) = 1,w); 2 2 W(A~ exp(A~)) W(0, A~ exp(A~)) --------------, ----------------2 2 A~ A~

and we must decide for ourselves just when each branch is appropriate. Once the weight parameter is identi ed by evaluating this function, the thrust speci c fuel consumption follows from c = ? log(w). Resolution of a Paradox in Physics

We give here a brief overview of the recent use of W in [10] to explain an anomaly in the calculation of exchange forces between the two nuclei within the hydrogen molecular ion (H ). In considering the one-dimensional limit of this system, namely the double-well Dirac delta function model, the wave equation in atomic units, (1) ? 21 ddx ? q [(x) + (x ? R)] = E () ; was used. The solution of this equation is expressed as a combination of atomic orbital solutions, viz, = Ae?cjxj + Be?cjx?Rj : (2) Making this solution continuous at each well (x = 0 and x = R) leads to the following transcendental equations for c: h i c = q 1  e?cR : (3) The solution of these equations can be expressed as c = q + W (qRe?qR)=R : (4) + 2

2

2

14

Lambert's W function These solutions are immediately available from Maple via the solve command. Scott et al. then go on to use this exact solution to explain how exponentially subdominant terms in the true asymptotic expansion of this solution account for discrepancies between the predictions of previous numerical and asymptotic solutions for the model equations. In brief, the exponentially subdominant terms were missing from the previous asymptotic developments, but are still signi cant for small enough R. Solution of a Linear Delay-Differential Equation

This application was communicated to us by Andre Heck. Many applied problems lead not to di erential equations but rather to delay-di erential equations, such as

y0(t) = ay(t ? s) :

(5)

If we substitute y(t) = exp( t) into this equation, where is yet to be determined, we see that we have found a solution provided that or

e t = ae t? s

(6)

s es = sa :

(7)

This equation can be solved in Maple to get

= 1s W (sa);

(8)

and we see immediately that if ?1=e < sa < 0 then there will be two real solutions to this equation, in contrast to the case for a pure di erential equation. If, further, a and y are complex, then there are an in nite number of solutions to this equation. Of course, this solution immediately generalizes to the case of nondefective systems of delay-di erential equations u0(t) = Au(t ? s), so that if we diagonalize A as A = PDP ? and let u = Py, then the system becomes y0 (t) = Dy(t ? s) and each component of this last equation can be solved as above. 1

Di erentiation

Di erentiating the de ning equation x = W (x)eW x for W and solving for W 0 , we obtain the following expressions for the derivative of W : W 0(x) = (1 + W (x))1exp(W (x)) (x) = x(1 W if x 6= 0 : + W (x)) ; ( )

Historically, it has been the case that symbolic algebra systems have been quite cavalier about the handling of exceptional points. The equation above is a typical example, for Maple V Release 2 will return the last expression given when asked to di erentiate W , and hence is able to compute W 0 (0) only as a limit. See [5] for further discussion of the handling of special cases (the so-called specialization problem) by computer algebra systems. 15

Lambert's W function

Computation of Series

The simplest series for W is the Taylor series about the origin. Euler knew this series, and it is possible that Lambert also did. The simplest way to derive this series is to use the Lagrange Inversion Theorem [11], which is not widely known, so we shall describe it. See the problems at the end for a direct method for computation of all terms in this series, and see also problem 20 for the important case of series about in nity. Notation: Given a function f which is analytic in a neighborhood of 0, denote by (n; f ) the coecient of xn in the power series expansion of f (x) at 0. Lagrange Inversion Theorem: Let U  C be an open neighborhood of 0 and let f : U ! C be analytic with f (0) 6= 0. Then there is an open neighborhood V of 0 and a unique analytic function g : V ! C which satis es g(x) = xf (g(x)). Furthermore, (n; g) = (n ? 1; f n)=n for n = 1; 2; : : : . Taking f (y) = e?y we have g = W , and we get the series expansion for W at 0:

W (z) =

1 (?n)n? X

1

n!

n

=1

zn :

(9)

This theorem provides a powerful way to revert some series, and in particular provides one of the very few methods available for nding all terms in a reverted series. However, we are often interested in reverting arbitrary series, and it will turn out in this article that we will want to revert three series for which the Lagrange Inversion Theorem doesn't help in actual computation. So a discussion of formal series reversion techniques at this point would be helpful. Formal Series Reversion

Given y as a function of x, we often want to `reverse' it to nd x as a function of y. Algebraically, we often can't succeed, at least not in `closed form'. With a table or graph, of course, it is very easy (see the problems). It is interesting that if we are working with series, this reversal is almost as simple as it is graphically, and in fact we can nearly always nd, given a series for y in terms of x, the `reverse' series for x in terms of y. Example 1

Suppose y = 2x ? 4x ? 6x + O(x ). When x = 0, y is also 0, so it seems reasonable to expect that, near the origin, x = a y + a y + a y + O(y ) for some as yet unknown a ; a ; and a . To nd the unknown coecients, we substitute the known series for y into this equation and equate powers of x (using the principle that if two Taylor series are equal, then their coecients must be equal). We get   x = a 2x ? 4x ? 6x + O(x ) 2

3

4

1

1

2

2

2

3

3

4

3

1

 

2

3

4

 

+ a 2x ? 4x ? 6x + O(x ) 2

2

3

4

+ a 2x ? 4x ? 6x + O(x ) +  : 3

16

2

3

4

2

3

Lambert's W function Now





2x ? 4x ? 6x + O(x ) = 4x ? 16x + O(x ) 2

and

3



2



2

4

2

2

3



4

2x ? 4x ? 6x + O(x ) = 8x + O(x )

so our equations become

3

3

4

3

4



x = a 2x ? 4x ? 6x + O(x )   +a 4x ? 16x + O(x )   +a 8x + O(x ) + = 2a x + (4a ? 4a )x + (8a ? 16a ? 6a )x + O(x ) : 1

2

2

3

4

3

4

3

3

4

2

1

2

3

1

3

2

4

1

Equating coecients of the powers of x, x , and x on both sides of the above equation, we get 2

3

1 = 2a ) a = 1=2 0 = 4(a ? a ) = 4a ? 2 ) a = 1=2 0 = 8a ? 16a ? 6a = 8a ? 11 ) a = 11=8 1

2

3

2

and so, at last, we have

1

1

2

1

2

3

3

x = y + y + y + O(y ) : 1

1

2

2

2

11

3

4

8

Example 2

Suppose y = (5 ? 2x)=(x ? 2) = 3 + 4(x ? 1) + 5(x ? 1) + 6(x ? 1) +    , and we wish to revert this series. Since we are expanding about x = 1 it makes sense to put x = x ? 1, so x is small for x near 1. Note that y = 3 when x = 1, so it makes sense to put y = y ? 3; then y will be small when x is small. We have reduced this case to a problem similar to our rst example by this transformation, 2

2

3

y = 4x + 5x + 6x +    2

3

and we wish to nd the coecients in the expansion

x = a y + a y + a y +    : 1

2

2

3

3

We put as before the known series for y into the form of the series for x, and equate coecients as before to get x = 1 + (y ? 3) ? (y ? 3) + (y ? 3) +    : The point of expansion of the original series is the constant term of the reverted series, and vice versa. In Maple, series reversion is very easy. The solve command checks its input, and if it is asked to solve for a series variable it uses series reversion techniques similar to those above. For the above example, we could have solved it in Maple by doing 1

5

4

64

2

13

3

512

17

Lambert's W function > series( (5-2*x)/(x-2)^2, x=1, 4);

2 3 4 3 + 4 (x - 1) + 5 (x - 1) + 6 (x - 1) + O((x - 1) )

>solve(y=",x);

/ 2 13 3 4 \ 1 + |1/4 (y - 3) - 5/64 (y - 3) + --- (y - 3) + O((y - 3) )| \ 512 /

which gives the same answer as before. An interesting subtlety of this approach in Maple is that the result of solve is not always a pure `series' type, and is sometimes dicult to manipulate in subsequent computations. In the above answer the practiced eye can discern that the answer returned from solve is of type `+', not of type `series', while the second operand in the sum is of type `series'. A call to series on this hybrid object removes any diculty. >series(",y=3,4);

Integration

2 13 3 4 1 + 1/4 (y - 3) - 5/64 (y - 3) + --- (y - 3) + O((y - 3) ) 512

Let us turn now to the question of integrating expressions containing W . At the Tenth Canadian Fluid Mechanics Symposium (1992) in St. John, New Brunswick, K. B. Ranger used the following di erential equation to illustrate some attempts to integrate the Navier-Stokes equations in parametric form. dy (10) dx = p

x = pep Di erentiating equation (11) with respect to y gives dx = dp ep + pep dp : dy dy dy

(11)

Simplifying using equation (10) we then obtain

dy = p(p + 1)ep ; dp which is easily integrated to give

y = (p ? p + 1)ep + C : 2

This example is pursued further in [8]. Since y is clearly an antiderivative of W (x), Ranger had discovered a simple technique for the symbolic integration of W (x). David Je rey was in the audience for this talk, and subsequently described the idea at the 1992 Maple Retreat. In our notation,

Z

18

W (x) dx = (W (x) ? W (x) + 1)eW x + C = x(W (x) ? 1 + 1=W (x)) + C ; if x 6= 0 : 2

( )

Lambert's W function When one tries this technique on other functions containing W , one sees that the technique is really a special change of variable: for example, on putting w = W (x), so x = wew and dx = (w + 1)ew , we see that

Z

Z

xW (x) dx =

wew  w  (1 + w)ew dw

= 81 (2w ? 1)(2w + 1)e w + C    W (x) ? W (x) + e W x + C : = 2

1

1

2

2

2

2

1

2

( )

2

This technique is valid for all branches of W , as by de nition dwd wew 6= 0 at any interior point of any branch. The problem of integrating functions containing W is a special case of integrating expressions R containing inverse functions. In the simplest form, one wants to nd f ? (x) dx, and from Ranger's work above, one can see that the method is simply to substitute x = f (y), obtaining 1

Z

Z

Z

f ? (x) dx = yf 0(y) dy = yf (y) ? f (y) dy 1

(12)

upon integrating by parts. In the more general form, one can use the same substitution to integrate

Z

G(x; f ? (x)) dx = 1

Z

G(f (y); y)f 0(y) dy

Z

d G(f (y); y) dy : = G(f (y); y)f (y) ? f (y) dy

This technique is not part of the standard calculus curriculum, even though it is not new. (It can be shown that equation R(12) is related to the Legendre Transform [2].) This technique allows a simpler derivation of sin? (x) dx than the standard method, and also allows for straightforward integration of more complicated expressions containing inverse functions, such R R ? as (sin (x)) dx and 1=(1+sin? (x)) dx. Maple currently cannot handle these last examples without manual intervention, but we have no doubt this will be recti ed. Finally, note that this technique allows the Risch decision procedure [6] to be applied to determine whether integrals containing W are elementary or not. In Maple V Release 2, we have the following examples. 1

1

1

3

> Int(x*W(x),x=0..t) = int(x*W(x),x=0..t);

Zt 0

?



(t) + 2 W (t) ? 1 + 1=8 W (x)xdx = t 4 W (t) ? 28W W (t) 2

3

2

2

> Int(sqrt(W(x)),x) = int(sqrt(W(x)),x) + C;

19

Lambert's W function

perf(ipW (x)) i x ? +C W (x)dx = W (x)x ? p 4 2 W (x)

Zq

q

Problems

Some of the following problems ask for series expansions. Most of these really ask only for computation of the rst few terms, but there are two questions which speci cally ask for in nite expansions. 1. Solve the di erential equation

dy = y (1 ? y); y(0) = 1=(u + 1) > 0 dt in terms of W . Find the asymptotic behavior of y(t), and series expansions valid for large u and small t. This is a model combustion problem studied in [7] and in [9]. 2. Find expressions for W 00 (x) and W 000 (x). 3. Find a recurrence relation that will enable you to eciently calculate W n (x) given the values of W (x); W 0 (x); : : : ; W n? (x). 4. Show that at x = ?1=e and W (x) = ?1 there is a derivative singularity of W . 2

(

(

)

1)

5. Verify that the reversion in example (1) is correct by plotting both series on the same graph. (Use x as the independent variable, running along the horizontal axis, for the rst series, and use y as the independent variable, running along the vertical axis, for the second). The graphs should not be completely identical, because they will di er by terms of O(x ), but they should match very closely, especially near the origin. 6. Revert the series from the previous question for x in terms of y to get a series for y in terms of x. Obviously this should be the same series as we started with in example (1). 7. Graph x = wew . `Reverse' this graph to graph the inverse function W (x). This is how Figure 1 was created. 8. In example (2), try instead to put x = a + a y + a y + a y +    and nd the unknown coecients. Graph your results. They should be bad, because y is not small and hence the terms of order y and higher are not negligible. 9. If we wanted an in nite number of terms in the previous expansion what would go wrong? 10. Graph the series from example (2) and its reversion on the same graph, and verify that the curves agree to fourth order. 11. Solve y = (5 ? 2x)=(x ? 2) for x, and then expand in series with respect to y about y = 3 directly, and compare with the previous problem. 12. Revert the following series by hand and verify with Maple. (a) y = 1 + x + x =2 + x =6 +    4

0

4

2

2

20

3

1

2

2

3

3

Lambert's W function (b) (c) (d) (e) (f) (g)

y = (x ? 1) ? (x ? 1) =2 + (x ? 1) =3 ?    y = x ? x =3! + x =5! ?    y = x ? x =3 + x =5 ?    y = 3 + 4x + x + O(x ) n n y = P1 n (?1) x x = w exp(w) = w + w =1! + w =2! + w =3! +    2

3

3

5

3

3

6

7

=0

2

3

4

13. Show that you cannot revert a series if the coecient of the linear term is zero. 14. If y = 3x ? 3x + 3x +   , p show that we can p nd a reversion for this that isn't a Taylor series: speci cally, that x = y=3 + y=6 + 3y =72 + O(y ). This type of series is called a Puiseux series. 2

3

4

2

3

15. Why is convergence of these series unimportant? 16. (Direct derivation of the Taylor series for W .) Suppose that

W (x) = w =

1 X k

P k ? wj and hence that Show that xk = 1 j k j ?k j

=

(

wk xk :

=1

k

)!

0k 1 1 X k?j X j w = @ (k ? j )! wj A wk : j k =1

Then deduce w = 1 and

=1

k j k?j X wj = 0 if k  2 : j (k ? j )!

1

=1

By inspection of the rst few terms of the series for W , as, for example, computed in ?1 ? n problem (12g) above, it is reasonable to guess that wn = n . Prove this by showing that k j k?j (?j )j ? X (k ? j )! j ! = 0 if k  2 : (

)

n

!

1

j

=1

17. Find a Pade approximant for W near x = 0. Convert it to continued fraction form. 18. Revert the series for z = wew about w = ?1 to obtain a Puiseux series for W (x) about the branch point x = ?1=e. In Maple V Release 2, this series can be used (with the negative square root taken) to get accurate values of W (x) near x = ?1=e. Can you nd this series' general term? 0

19. Convert the series expansion of the previous question to rational form and investigate its accuracy. 21

Lambert's W function 20. Asymptotic series. Put W (x) = log x ? log(log x) + v(x) and W (x) = log(?x) ? log(? log(?x)) + v (x). Show that v satis es 0

0

1 ?  + v = e?v ; where  = 1= log(x) and  = log(log x)= log x, and that v satis es a similar equation. Solve this equation for  , and expand  in a series about v = 0. Revert this series (in Maple) to get an expansion for v valid for large x, and an expansion for v valid for small negative x. See [4] for a proof that these series converge, and for extensions to the complex-variable case. 0

0

21. Evaluate the following integrals. (a) (b) (c) (d) (e) (f) (g) (h) (i)

R xW (x) dx R 1=W (x) dx R x=W (x) dx R W (x) log x dx R 1=(1 + W (x)) dx R sin (W (x)) dx R log x log (W (x)) dx R W (x)? dx R 1=(1 + sin? x) dx 5

1

Concluding Remarks

This article, and the paper [4], were written to satisfy a long-standing need for more complete information about Lambert's W function. The work proved to be interesting in itself, and we have enjoyed our explorations. We hope that you have also enjoyed these explorations, and are now inclined to treat W as \one of the family".

Acknowledgements

Our thanks go to Tony Scott for providing an excellent motivational application of Lambert's W function, and to Jon Borwein for pointing out the connection between equation (12) and the Legendre Transform. We also thank Bruno Salvy for interesting discussions. This work was supported by NSERC and by ITRC.

References [1] J. D. Anderson, Introduction to Flight, 3rd ed., McGraw-Hill, New York, (1989). [2] V. I. Arnold, Mathematical Methods for Classical Mechanics, Springer-Verlag, (1978). [3] B. W. Char, K. O. Geddes, G. H. Gonnet, B. L. Leong, M. B. Monagan, and S. M. Watt, The Maple V Language Reference Manual, Springer-Verlag, New York, (1991). 22

Lambert's W function [4] R. M. Corless, G. H. Gonnet, D. E. G. Hare, and D. J. Je rey, \On Lambert's W function", Technical Report CS-93-03, Dept. Comp. Sci., University of Waterloo, (1993). [5] R. M. Corless and D. J. Je rey, \Well, It Isn't Quite That Simple", SIGSAM Bulletin, 26 (1992), 2{6. [6] K. O. Geddes, S. R. Czapor, and G. Labahn, Algorithms for Computer Algebra, Kluwer Academic Publishers, (1992). [7] R. E. O'Malley, Jr., Singular Perturbation Methods for Ordinary Di erential Equations, Springer-Verlag Applied Mathematical Sciences, 89, (1991). [8] K. B. Ranger, \A complex variable integration technique for the 2-dimensional Navier{ Stokes equations", Q. Applied Maths, 49, pp.555-562, (1991), [9] E. L. Reiss, \A new asymptotic method for jump phenomena", SIAM J. Appl. Math, 39, pp.440-455, (1980). [10] T. C. Scott, J. F. Babb, A. Dalgarno, and John D. Morgan III, \The Calculation of Exchange Forces: General Results and Speci c Models", submitted (1993); also \Resolution of a Paradox in the Calculation of Exchange Forces for H ", Chem. Phys. Lett., 203, p.175, (1993). [11] E. C. Titchmarsh, Theory of Functions, 2nd ed., Oxford, (1939). + 2

23