I'm trying to plot the x!
function in gnuplot, I defined first the factorial function and then called it, but I'm always getting stack overflow, no matter what bounds I set to the graph.
This what I've tried:
gnuplot> fac(n) = (n==0) ? 1 : n * fac(n-1)
gnuplot> plot [0:10][0:10] log(fac(x)), log(x**x)
stack overflow
I should define the fac function to be integer. Otherwise, when plotting all along the x-axis, it'll evaluate a long range of real numbers, a huge one actually, which will always cause the overflow.
So, the function should be defined:
fac(x) = (int(x)==0) ? 1.0 : int(x) * fac(int(x)-1.0)
Another soultion would be to use the Gamma function (intrinsic function in gnuplot).
N!=gamma(N+1)
gnuplot> plot [0:10][0:10] log(gamma(x+1)), log(x**x)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With