# Lambert W function with natural log

I need to solve the next equation x:

$d-x+yln[\frac{d}{x}]=b$

I inserted this into Wolfram Alpha and it returned:

$x = y \Bbb{W}[\frac{e^\frac{d-b}{y}d}{y})]$

y, d, b, and x are all real, positive numbers.

How do I solve for x by implementing the lambert W function?

Thanks!

• Yes, that $\mathbb W$ is the Lambert W function. – Robert Israel Apr 5 '16 at 15:37
• Welcome to math stack exchange! – Peter Apr 5 '16 at 16:17
• Um, doesn't $W(0)=0\implies\frac0{W(t)}=0\implies\ln(0)=undefined?$ – Simply Beautiful Art Apr 5 '16 at 21:22
• W(0) is the initial weight of something at time 0 so W(0) does not equal 0 for this problem. – Christina Apr 6 '16 at 18:31
• "How do I solve for $x$ by implementing the Lambert $W$ function?" what is the problem, you have the answer? – Yves Daoust Apr 12 '16 at 13:16

This answer gives the following method for computing Lambert W:

Analysis of $we^w$

For $w\gt0$, $we^w$ increases monotonically from $0$ to $\infty$. When $w\lt0$, $we^w$ is negative.

Thus, for $x\gt0$, $\mathrm{W}(x)$ is positive and well-defined and increases monotonically.

For $w\lt0$, $we^w$ reaches a minimum of $-1/e$ at $w=-1$. On $(-1,0)$, $w e^w$ increases monotonically from $-1/e$ to $0$. On $(-\infty,-1)$, $w e^w$ decreases monotonically from $0$ to $-1/e$. Thus, on $(-1/e,0)$, $\mathrm{W}(x)$ can have one of two values, one in $(-1,0)$ and another in $(-\infty,-1)$. The value in $(-1,0)$ is called the principal value.

The iteration

Using Newton's method to solve $we^w$ yields the following iterative step for finding $\mathrm{W}(x)$: $$w_{\text{new}}=\frac{xe^{-w}+w^2}{w+1}$$

Initial values of $w$

For the principal value, when $-1/e\le x\lt0$, and when $0\le x\le10$, use $w=0$. When $x\gt10$, use $w=\log(x)-\log(\log(x))$.

For the non-principal value, when $x$ is in $[-1/e,-.1]$, use $w=-2$; and if $x$ is in $(-.1,0)$, use $w=\log(-x)-\log(-\log(-x))$.

• If I may : one of these days, if you have time to waste, could we go to a chat room ? I would like to discuss with you about algorithms for solving $x=w e^w$. I leave that to your initiative. Just for your information : I am available between 6:00am and 1:00pm on French time. Thanks and cheers. – Claude Leibovici Nov 26 '16 at 9:54
• I am often in the Math Chat Room. – robjohn Nov 26 '16 at 11:13

Not sure if this'll help. You've probably read by now that the Lambert W-Function is defined as the inverse relation of $xe^x$. That is to say, $W(xe^x)=x$.

You can usually just leave the $W$ function as it is, or make a numerical computation using WolframAlpha, or various numerical methods (Newton's method, Halley's method, etc.) to approximate it.

So, if you want to plug in $d,b,y$ values to find the various $x$-values, then you'll just need to use numerical methods to solve it (see @robjohn's answer).

There is no way to further simplify. The reason the function even exists, is because it is a special function which has been defined for this purpose. You can't express it in terms of elementary functions.

Now, to get the Wolfram result:

$d-x+y\ln[\frac{d}{x}]=b$

$d-x+y[\ln d-\ln x] =b$

$x+y\ln x =y\ln d+d-b$

$m=y\ln d+d-b$

$x+y\ln x=m$

$\frac{x}{y}+\ln x=\frac{m}{y}$

$xe^{\frac{x}{y}}=e^{\frac{m}{y}}$

$\frac{x}{y} e^{\frac{x}{y}} = \frac{1}{y} e^{\frac{m}{y}}$

Taking the product log of both sides, we end up with:

$\frac{x}{y} = W[\frac{1}{y} e^{\frac{m}{y}}]$

So, solving for $x$, we get that:

$x = y W[\frac{1}{y} e^{\frac{m}{y}}]$

To get the result in the form of Wolfram's answer, just substitute back in for $m$:

$x = y W[\frac{1}{y} e^{\frac{y\ln d+d-b}{y}}]$

$x = y W[\frac{1}{y} e^{\ln d+\frac{d-b}{y}}]$

$x = y W[\frac{1}{y} d e^{\frac{d-b}{y}}]$

And that's as far as we can get. If you want to numerically evaluate $x$, then you can either use iterative processes, such as are on the Wikipedia page, or just use Wolfram to calculate.