Gamma Function plot

Gamma Function plot Using Scipy

from scipy import special
from pylab import *
def f(x):
    return special.gamma(x)
x = linspace(-6, 6, 512)
y = f(x)
plot(x, y)
xlabel('x')
ylabel('y')
axis([-6, 6, -100, 100])
grid(True)
 show()


Gamma Function Plot Using Core python:

from pylab import*
def gamma(x):
    a=[1,76.18,-86.505,24.014,-1.232]
    k=x+5.5
    s=(k-5)*log(k)-k
    s1=a[0]
    for i in range(1,5):
        s1+=a[i]/(x+i)
    return exp(s+log(sqrt(2*pi)*s1/x))
p=linspace(-5,6,1000)
z=gamma(p)
plot(p,z)
axis([-5,7,-1,150])
xlabel('x')
ylabel('Gamma funtion')
title('Plot of Gamma funtion')
grid(True)
show()

Comments