In [1]:
%pylab inline
from scipy.special import *
In [2]:
x=linspace(-4,4,1000)
figure(figsize=(12,6))
ylim(-6,6)
grid()
fs=30
xticks(linspace(-4,4,9),fontsize=fs);yticks(fontsize=fs);
xlabel(r'$x$',fontsize=fs)
ylabel(r'$\Gamma(x)$',fontsize=fs)
plot([-4,4],[0,0],'k-')
plot(x,gamma(x),lw=3);
savefig('Gamma.png',pad_inches=0.0,bbox_inches='tight')
In [3]:
t=linspace(0,8,1000)
figure(figsize=(12,6))
fs=30
nn=2.3
plot(t,exp(-t)*t**nn,'r-',label=r'$e^{-t}t^n$',lw=3)
plot(t,exp(-t),'b--',label=r'$e^{-t}$',lw=3)
plot(t,t**nn,'-',color='orange',label=r'$t^n$',lw=3)
plot(t,exp(-(nn-nn*log(nn)))*exp(-(t-nn)**2/(2*nn)),'k:',lw=4,label=r'$e^{-(n-n\log n)}e^{-\frac{(t-n)^2}{2n}}$')
ylim(0,1)
grid()
xlabel(r'$t$',fontsize=fs)
xticks(fontsize=fs);yticks(fontsize=fs);
legend(fontsize=fs);
savefig('Stirling.png',pad_inches=0.0,bbox_inches='tight')
In [4]:
x=linspace(0,4,1000)
figure(figsize=(12,6))
ylim(0,6)
grid()
fs=30
xticks(linspace(0,4,5),fontsize=fs);yticks(fontsize=fs);
xlabel(r'$x$',fontsize=fs)
#ylabel(r'$\Gamma(x)$',fontsize=fs)
#plot([0,4],[0,0],'k-')
plot(x,gamma(x),lw=3,label=r"$\Gamma(x)$");
x=linspace(1.0001,4,1000)
plot(x,(x-1)**(x-1)*exp(-(x-1))*sqrt(2*pi*(x-1)),'r--',lw=5,label="Stirling-formula")
legend(fontsize=fs,loc=2)
savefig('Stirling-approx.png',pad_inches=0.0,bbox_inches='tight')