13
$\begingroup$

I have an equation of the form:

$$ n \log n = x $$

Upon searching I came across the term "Lambert- W -Function" but couldn't find a proper method for evaluation, and neither any computer code for it's evaluation.

Any ideas as to how I can evaluate?

$\endgroup$
  • $\begingroup$ Do you mean an evaluation of the function for a certain argument? Sorry, just trying to make sure I understand your question. $\endgroup$ – Sheheryar Zaidi Sep 21 '14 at 8:39
  • $\begingroup$ Well,this is more of a programming question,but was just wondering if it could be solved manually. For given value of x,can we find n? $\endgroup$ – techriften Sep 21 '14 at 8:41
  • $\begingroup$ mathworld.wolfram.com/LambertW-Function.html give several series expansions. See the equations (11), (13) and (14). $\endgroup$ – Nabigh Sep 21 '14 at 8:43
  • $\begingroup$ wikipedia has a derivate containing code ("wikicode"? "Rosettastone"?). I found it easy to find a recursive programming-example, translatable into Pari/GP $\endgroup$ – Gottfried Helms Sep 21 '14 at 8:49
  • $\begingroup$ $n\ln(n)=x\implies \exp(n\ln(n))=\exp(x)\implies n^n=\exp(x)\implies n=\frac{x}{W(x)}$, using Example 2 of the wiki article on $W$. $\endgroup$ – Yiannis Galidakis Sep 21 '14 at 9:11
7
$\begingroup$

Let us consider the function $$f(x)=x \log(x)-a$$ Effcetively, the solution of $f(x)=0$ is given by $$x=\frac{a}{W(a)}$$ and, if I properly understood, you look for a computation method for getting $W(a)$.

From definition $W(a)$ is defined such that $a=W(a)e^{W(a)}$ so Newton method seems to be (and is) very good.

I strongly suggest you have a look at http://en.wikipedia.org/wiki/Lambert_W_function. In the paragraph entitled "Numerical evaluation", they give Newton and Halley formulae (the latest one has been massively used by Corless et al. to compute $W(a)$.

In the same Wikipedia page, you will find very nice and efficient approximations of $W(a)$ for small and large values. These estimates will allow you to start really close to the solution.

If I may underline one thing which is really nice : all derivatives od $W(a)$ express as functions of $a$ and $W(a)$ itself and this is extremely convenient.

You could be interested by http://people.sc.fsu.edu/~jburkardt/cpp_src/toms443/toms443.html where the source code is available.

| cite | improve this answer | |
$\endgroup$
3
$\begingroup$

Although an old post, I'm surprised nobody mentioned this:

$$n\log n=(e^{\log n})\log n=x$$

Now it should be obvious on how to proceed.

$$W(x)=\log n$$

$$e^{W(x)}=n$$

And because $W(x)e^{W(x)}=x$, $e^W(x)=\frac{x}{W(x)}$ so,

$$\frac{x}{W(x)}=n$$

| cite | improve this answer | |
$\endgroup$
2
$\begingroup$

If you're using Matlab or want to look at a robust (but simple) implementation of the Lambert $W$ function ($W_0$ branch only) using Halley's method, see my answer here.

As an alternative to @ClaudeLeibovici's more general answer, an equation specifically of the form $n \text{ln}(n) = x$ might best be solved and analyzed using the simpler Wright $\omega$ function:

$$n = \frac{x}{\omega(-ln(1/x))}$$

Matlab has wrightOmega and Maple has Wrightomega to evaluate this function symbolically. See Corless and Jeffrey, 2002, The Wright omega Function (PDF) for further details. Unfortunately, there does not seem to be support for this function in SciPy or SymPy.

The Wright $\omega$ function can also be evaluated numerically. See Lawrence, et al., 2012, Algorithm 917: Complex Double-Precision Evaluation of the Wright ω Function. I've implemented this algorithm in Matlab – you can find it on GitHub here. Evaluating this numerically is 3+ orders of magnitude faster than evaluating it symbolically. If your $x$ parameter is constrained in particular ways (e.g., real-valued), you may be able to simplify your algorithm – see the Lawrence, et al. paper and the comments in my wrightOmega code.

| cite | improve this answer | |
$\endgroup$
2
$\begingroup$

Although this has already been answered, I think a step by step explanation is more informative than a general one.

The following is my attempt:

\begin{align*} n \ln (n) =x \quad & \Rightarrow \quad \ln n^n=x \\ & \Rightarrow \quad n^n=e^x \\ & \Rightarrow \quad n=e^{x/n} \\ & \Rightarrow \quad n \times \frac{x}{n}=\frac{x}{n}e^{x/n} \\ & \Rightarrow \quad x=\frac{x}{n}e^{x/n} \\ & \Rightarrow \quad W(x)=W \left(\frac{x}{n}e^{x/n} \right) \\ & \Rightarrow \quad W(x)=\frac{x}{n} \\ & \Rightarrow \quad \boxed{n=\frac{x}{W(x)}} \\ & \Rightarrow \quad n=\frac{x}{x/e^{W(x)}} \quad \text{(since $W(x)e^{W(x)}=x$)}\\ & \Rightarrow \quad \boxed{n=e^{W(x)}} \\ \end{align*}

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ How do we replace $\log(x)$ with $\ln(x)$? $\endgroup$ – Mathrix Mar 30 at 0:37
  • $\begingroup$ @Mathrix Often \log is used as \ln. Sometimes (mostly on calculators) it stands for \log_10. $\endgroup$ – Daniel Sep 7 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.