Using Lambert W to solve n*log(n) = c

  • Thread starter wwshr87
  • Start date
In summary: I intend to solve the following problem n*log(n)=c, where log is base 10.In summary, the equation n*log(n) = c can be expressed as n = 10^(c/n) and solved using a numerical method such as the Lambert W function. This function solves the problem x*e^(x)=c for a constant c. However, for very large values of c, the Lambert W function may not converge. To solve this, one can use the asymptotic series development of the Lambert W function. Alternatively, for values of c such as 10^(10^9), the simple fixed point iteration method can be used for accurate results.
  • #1
wwshr87
59
0
I intend to solve the following problem n*log(n)=c, where log is base 10.

n*log(n)=c, expressing this as n=10^(c/n), then this becomes n^n=10^c.

Now this can be solved using a numerical method such as Lambert W function.

The Lambert W function solves the problem x*e^(x)=c, where c is a constant, we can use

this to solve our problem. ln(x)*e^(ln(x))= ln(c).

Lets say I want find n*log(n)=100, then using this method I find n=56.9612. Which is

correct, but what happens as c approaches a very large value such as 10*10^9? Is there

no solution for this? This is an assignment but I am getting infinity as a solution since c

is too large, any ideas?
 
Mathematics news on Phys.org
  • #2
That's a problem of computers, which can't handle too large or too small numbers. The mathematic problem always has a solution, the informatic one not!

A trick would be (but I don't know if it works) to solve, instead of

[tex]n^n=c[/tex]

the equivalent equation

[tex]n^{\frac{n}{10^k}}=c^{\frac{1}{10^k}}[/tex]

This way the number on the right is much smaller than c, so maybe you can avoid overflow.
 
  • #3
wwshr87 said:
Lets say I want find n*log(n)=100, then using this method I find n=56.9612. Which is

correct, but what happens as c approaches a very large value such as 10*10^9?

Numerical methods work well. Here's Brent's method in Pari/GP:
Code:
> solve(n=1,9e9,n*log(n)/log(10)-100)
time = 0 ms.
%1 = 56.961248432260820305122298236945720381
> solve(n=1,9e9,n*log(n)/log(10)-10*10^9)
time = 0 ms.
%2 = 1105747502.5934196047121510163796270508
 
  • #4
Petr Mugver said:
That's a problem of computers, which can't handle too large or too small numbers.
I assume what you meant to say is "that is a problem of calculators that weren't programmed to work with large or small numbers", and have implicitly assumed our goal is to enumerate a decimal string.
 
  • #5
I am sorry, I made a mistake. The value c=10^(10^9), which in MatLab is inf.

I will look into Brent's method and see what I can do.

Thank you.
 
  • #6
wwshr87 said:
I am sorry, I made a mistake. The value c=10^(10^9), which in MatLab is inf.

Code:
solve(n=1,10^1e9,n*log(n)/log(10)-10^1e9)
time = 0 ms.
%3 = 1.0000000090000000770913503056206873776 E999999991
although in this case the answer is good to only 30 decimal places.

wwshr87 said:
I will look into Brent's method and see what I can do.

If you're going to write it on your own, I recommend the secant method instead. For this problem it's just as good, and much easier to implement.
 
  • #7
Indeed, equation x*ln(x)=c can be numerically solved, even for large c.
It is also possible to solve it in term of the Lambert W function x=exp(W(c)).
In case of large c, one can use the asymptotic series development of the LambertW function. For example, see formula (15) in :
http://mathworld.wolfram.com/LambertW-Function.html
Of course the series can be reduced to a lower number of terms, depening on the needed accuracy.
 

Attachments

  • LambertW.JPG
    LambertW.JPG
    9.9 KB · Views: 648
  • #8
wwshr87 said:
I intend to solve the following problem n*log(n)=c, where log is base 10.

n*log(n)=c, expressing this as n=10^(c/n), then this becomes n^n=10^c. Now this can be solved using a numerical method such as Lambert W function.

The Lambert W function solves the problem x*e^(x)=c, where c is a constant, we can use this to solve our problem. ln(x)*e^(ln(x))= ln(c).

Lets say I want find n*log(n)=100, then using this method I find n=56.9612. Which is correct, but what happens as c approaches a very large value such as 10*10^9? Is there no solution for this? This is an assignment but I am getting infinity as a solution since c is too large, any ideas?

Im assuming that you've already figured out the solution is:

[tex]n=e^{W(c \ln(10))}[/tex].

I don't see what's the problem with evaluating the lambert W function for large arguments. I tried both Newtons method and a fixed point iteration and had no convergence problems with either.

The simple fixed point iteration : w = ln(x/w) converges accurate 10 significant figures only 8 iterations for c=10^10 (and of course x = c ln(10) as required in the above solution).

Note: I'm finding W(x) by solving for "w" in "w e^w = x", using starting value of w=ln(x) for the fixed point iterations.
 
Last edited:
  • #9
CRGreathouse said:
Code:
solve(n=1,10^1e9,n*log(n)/log(10)-10^1e9)
time = 0 ms.
%3 = 1.0000000090000000770913503056206873776 E999999991
although in this case the answer is good to only 30 decimal places.
If you're going to write it on your own, I recommend the secant method instead. For this problem it's just as good, and much easier to implement.

Hi CRGreathouse. The OP said 10*10^9 not 10^(10^9). :)
 
  • #10
uart said:
Hi CRGreathouse. The OP said 10*10^9 not 10^(10^9). :)

See post #5.
 
  • #11
CRGreathouse said:
See post #5.
Whoops, I missed that correction.
 
  • #12
In that case the OP definitely should go with the asymptotic solution mentioned above by JJacquelin. It will converge quite rapidly given that (L1=log(c)) >> (L2 = log(log(c))) and it is especially easy to caclulate due to the convienient properties of "log". Even for c=10^(10^9) it's straight forward to evaluate L1 and L2 with just a pocket calculator!
 

1. What is the Lambert W function?

The Lambert W function, also known as the product logarithm or omega function, is a special function that is defined as the inverse of the function f(x) = xe^x. It is denoted by W(x) and is used to solve equations of the form x = f(x), such as n*log(n) = c.

2. How does the Lambert W function work?

The Lambert W function is a complex-valued function that has two branches: the principal branch and the secondary branch. The principal branch is defined for values of x ≥ -1/e, while the secondary branch is defined for values of -1/e ≥ x > -1. It can be used to solve equations of the form x = f(x) by rearranging the equation and applying the W function to both sides.

3. How is the Lambert W function used to solve n*log(n) = c?

To solve an equation of the form n*log(n) = c, we can rearrange the equation to be in the form x = f(x), where x = n and f(x) = x*log(x). Then, we can apply the Lambert W function to both sides, giving us W(n) = W(c). We can then solve for n by evaluating the Lambert W function at c and solving for n.

4. What are the applications of using Lambert W to solve n*log(n) = c?

The Lambert W function has many applications in mathematics, physics, and engineering. It is commonly used in the analysis of algorithms to determine the time complexity of certain algorithms. It also has applications in economic and financial models, as well as in population growth models.

5. Are there any limitations to using the Lambert W function to solve n*log(n) = c?

While the Lambert W function is a powerful tool for solving equations of the form x = f(x), it has some limitations. One limitation is that it can only be used to solve equations where the variable appears both inside and outside of a logarithm. Additionally, the Lambert W function can only be evaluated numerically, so it may not give an exact solution in some cases.

Similar threads

  • General Math
Replies
3
Views
1K
  • General Math
Replies
9
Views
2K
Replies
1
Views
864
  • Calculus
Replies
27
Views
2K
Replies
10
Views
2K
Replies
6
Views
2K
  • General Math
Replies
6
Views
1K
Replies
1
Views
9K
  • General Math
Replies
4
Views
1K
Replies
5
Views
1K
Back
Top