Can we obtain $\sum_{i=1}^n a_i$ from $\sum_{i=1}^n \log a_i$?

67 Views Asked by At

Is there a way to obtain $\sum_{i=1}^n a_i$ from $\sum_{i=1}^n \log a_i$? Actually I am trying to compute $\sum_{n=1}^{1000} n!/n^n$ using matlab, but since $n!$ and $n^n$ grows too fast as $n$ becomes large, it is only possible to get $\sum_{n=1}^{k} n!/n^n$ for $k\leq 170$. I have a hint to use the identity $\exp (\log f(x))=f(x)$ to handle this problem, but I cannot see how to use it because I don't know any way to obtain $\sum_{i=1}^n a_i$ from $\sum_{i=1}^n \log a_i$. Should I use the hint in another way?

1

There are 1 best solutions below

1
On BEST ANSWER

"it is only possible to get $\sum_{n=1}^{k} n!/n^n$ for $k\leq 170$." It is not clear to me why do you think this. I assume that you are trying to calculate the numerator and denominator separately for each term of the series: $$\frac{n!}{n^n}=\frac{(1\cdot2\cdot 3\cdot\ldots\cdot n)}{(n\cdot n\cdot n\cdot\ldots\cdot n)}$$ and at some point you get overflow $\frac{\infty}{\infty}=\operatorname{Nan}$, since both the numerator and denominator are out of the range of the IEEE double.

But nothing stops you to calculate this way:

$$\frac{n!}{n^n}=\left(\frac{1}{n}\right)\cdot\left(\frac{2}{n}\right)\cdot\left(\frac{3}{n}\right)\cdot\ldots\cdot\left(\frac{n}{n}\right)$$ ... and the overflow is gone!

Yet another way to avoid the overflow (following the hint) is to write:

$$\frac{n!}{n^n}=\exp{\ln\left(\frac{n!}{n^n}\right)}=\exp\left(\ln 1+\ln 2+\ldots+\ln n - n\ln n\right)$$