I am a fairly new user to Mathematica and I am strugling with one problem.

I would like to run a simulation to figure it out how long the sequence of $\frac{1}{n}$ as $n \rightarrow \infty $ needs to be, for its summation to achieve 200.

$\sum_{n=1}^{k}{\frac{1}{n}} \ge 200$

I am not as familiar with Mathematica coding. My code so far looks like this:

i = 0
n = 1
While[i < 200, i = ((1/n) + (1/(n + 1)))]; n++]

I would appreciate the help with this.


The partial sum is the definition of the HarmonicNumber

h[m_] = Sum[1/n, {n, 1, m}]

(*  HarmonicNumber[m]  *)

An alternate representation is

h[m] // FunctionExpand

(*  EulerGamma + PolyGamma[0, 1 + m]  *)

To find the value of m for which the sum is 200

soln = Solve[h[m] == 200, m][[1]] // N // Quiet

(*  {m -> 4.0570915001197426*^86}  *)

h[m] /. soln

(*  200.  *)
  • $\begingroup$ Yeah, I was gonna say that running a while loop to figure this out might take a while as the number of terms will be ridiculously large. $\endgroup$ – Fixed Point Oct 19 '16 at 16:28
  • $\begingroup$ I didn't know how to use a Mathematica syntax and running a loop in R didn't get me anywhere. Thanks for the help! $\endgroup$ – Andraž Poje Oct 20 '16 at 7:26

You can get it accurately using FindInstance:

FindInstance[HarmonicNumber[k] == 200, k]

{{k -> Root[{-200 + HarmonicNumber[#1] &, 4.05709150011974242417272921508*10^86}]}}

Note that HarmonicNumber[k] is simply the sum up to k:

Sum[1/n, {n, k}]


So your answer is 4.05709150011974242417272921508*10^86 and change!


The correct solutions have already been given. It might be interesting that you can solve the problem with a pocket calculator to a high degree of accuracy using the formula

$$\sum _{n=1}^m \frac{1}{n}\simeq \log (m)+\gamma$$

Where $\gamma$ is the Mathematica constant EulerGamma which has the value

EulerGamma // N

(* Out[79]= 0.577216 *)

We find the index by solving $\log (m)+\gamma =200$ for m

mm = m /. N[Solve[EulerGamma + Log[m] == 200], 12][[1]]

(* Out[77]= 4.05709150012*10^86 *)

(This can obviously be done with a pocket calculator).


Sum[1/n, {n, 1, m}] /. m -> mm

(* Out[78]= 200.000000000000 *)

Remark: The order of magnitude (power of 10) is simply given by ignoring $\gamma$ to be

Exp[200] // N

(* Out[81]= 7.22597*10^86 *)

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.