One of the key maths functions used in quantum technology. It is often referred to as the generalized factorial, this is a standard as per NIST Digital Library of Mathematical Functions https://dlmf.nist.gov/5.2#E1
1. In [11]: # Orignal-source/copyrights of:Sci Py website,https://docs.scipy.org/
# Demonstration of use of gamma function
from scipy.special import gamma, factorial #import function from library
In [12]: gamma([0, 0.5, 1, 5])#scipy.special.gamma(z, out=None) = <ufunc 'gamma'>
In [13]: z = 2.5 + 1j # Initialize a complex number
gamma(z) # Pass the complex number to gamma function
In [14]: import numpy as np #import numpy from libraries
x = np.linspace(-3.5, 5.5, 2251) #numpy.linspace(start, stop, num=50, end
point=True, retstep=False, dtype=None, axis=0)
y = gamma(x)
In [15]: import matplotlib.pyplot as plt #import pyplot from libraries
plt.plot(x, y, 'b', alpha=0.6, label='gamma(x)') #pass gamma as a input t
o the plot
k = np.arange(1, 7) # define range
plt.plot(k, factorial(k-1), 'k*', alpha=0.6,
label='(x-1)!, x = 1, 2, ...')
plt.xlim(-3.5, 5.5) # define plt x limit
plt.ylim(-10, 25) # define plt y limit
plt.grid()
plt.xlabel('x')
plt.legend(loc='lower right')
plt.show() # draw plot
In [16]: # Original link 2022: https://docs.scipy.org/doc/scipy/reference/generate
d/scipy.special.gamma.html#scipy.special.gamma
# Executed by Bhadale IT, in Anaconda Jupyter Notebook
# No copyright infringement intended, for educational purpose only
Out[12]: array([ inf, 1.77245385, 1. , 24. ])
Out[13]: (0.77476210455108419+0.70763120437959348j)
NIST_Fns http://localhost:8888/nbconvert/html/NIST_Fns.ipynb?download=false
1 of 1 24-Oct-22, 12:50 PM