Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I was plotting the relative error of the $e^{11/12 -n}n^{n+1/2}$ approximation to $n!$ as $n$ gets larger and larger, and at some very large value of $n$ Mathematica gives this plot:

enter image description here

Can somebody explain what exactly the plot means? Of course, I understand that, for larger and larger $n$, the relative error tends to a limit, but I am not sure how to interpret this plot. In particular, I don't understand how the error can show greater variation as $n$ grows large.


Edit: I want to add that when $n$ is an order of magnitude less what I get is something like this:

share|improve this question

marked as duplicate by Mr.Wizard Jul 19 '13 at 0:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

This sounds more like a math question to me. Are you asking why it levels off as n grows larger? – cartonn Dec 10 '12 at 0:37
Similar questions:… – xzczd Dec 10 '12 at 3:17
up vote 3 down vote accepted

Looks like numerical error, try increasing the WorkingPrecision

Plot[Abs[(Exp[11/12 - n] n^(n + 1/2) - n!)/n!]
   ,{n, 10, 10^7}
   ,WorkingPrecision -> 100]


WorkingPrecision is an option for various numerical operations that specifies how many digits of precision should be maintained in internal computations.

Edit You might also find Limit interesting

Limit[(Exp[11/12 - n] n^(n + 1/2) - n!)/n!, n -> Infinity]
(* -1 + E^(11/12)/Sqrt[2 \[Pi]] *)
(* -0.0022692878024401615486447545367879811325821284314703  *)
share|improve this answer

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