I want to plot to show how accurate is Stirling approximation in Mathematica by plotting the Percentage error against n. I want to take the value of n at the interval of 10 starting from 10 to 1000. So, I basically used the Listplot function to plot all these datas, which has been rather tedious. Is there any way simpler method to plot this approximation $\ln n!=n\ln n-n$
2 Answers
Although n is allowed to take non integer values, you probably intend it to take only integer values, so this is a job for DiscretePlot
DiscretePlot[Log[n!]/(n Log[n] - n), {n, 10, 1000, 10},
PlotRange -> All, Frame -> True]
-
$\begingroup$ As an addendum, you can see how fast the relative error tends to zero with
Simplify[Series[1 - Log[n!]/(n Log[n] - n), {n, \[Infinity], 4}], n > 0]
$\endgroup$ Nov 27, 2014 at 22:16 -
$\begingroup$ Can we manipulate the plot by using manipulate function ? $\endgroup$ Nov 27, 2014 at 23:22
-
$\begingroup$ In principle, yes, but I don't see a useful free parameter to manipulate here. $\endgroup$ Nov 27, 2014 at 23:33
-
1$\begingroup$ There is no reason to restrict n to be an integer so you could also use
Plot
.Manipulate[Plot[Log[n!]/(n Log[n] - n), {n, nmin, nmax}, PlotRange -> All, Axes -> False, Frame -> True], {{nmin, 10}, 10, 999, 1, Appearance -> "Labeled"}, {{nmax, 1000}, nmin + 1, 1000, 1, Appearance -> "Labeled"}]
$\endgroup$ Nov 27, 2014 at 23:40
Plot[Log[n!] - (n Log[n] - n), {n, 1, 1000}]
shows the error between the two functions. You can divide by n
to get percentage error...