The Python math.gamma() method calculates the gamma method, denoted as Γ. It is a mathematical extension of the factorial() method to non-integer values. The gamma method is defined for all complex numbers except non-positive integers.
Mathematically, the gamma method is defined as −
$$\mathrm{\Gamma(x)\:=\:\int_{0}^{∞}\:t^{x-1}e^{-t}dt}$$
Where, e is the base of the natural logarithm. The gamma method has various properties, they are as follows −
Following is the basic syntax of the Python math.gamma() method −
math.gamma(x)Parameters
This method accepts a real number or a numeric expression as a parameter for which you want to calculate the gamma method.
Return ValueThe method returns the value of gamma method evaluated at x.
Example 1In the following example, we are calculating the gamma method for a positive integer using the math.gamma() method −
import math x = 5 result = math.gamma(x) print("Gamma method for x =", x, ":", result)Output
The output obtained is as follows −
Gamma method for x = 5 : 24.0Example 2
In here, we are calculating the gamma method for a positive real number using the math.gamma() method −
import math x = 2.5 result = math.gamma(x) print("Gamma method for x =", x, ":", result)Output
Following is the output of the above code −
Gamma method for x = 2.5 : 1.3293403881791372Example 3
In this example, we are evaluating the product of gamma methods for x=3 and x + 1 using the math.gamma() method −
import math x = 3 result = math.gamma(x) * math.gamma(x+1) print("Expression result for x =", x, ":", result)Output
We get the output as shown below −
Expression result for x = 3 : 12.0Example 4
Now, we use the math.gamma() method to calculate the gamma method for a negative number −
import math x = -3.5 result = math.gamma(x) print("Gamma method for x =", x, ":", result)Output
The result produced is as shown below −
Gamma method for x = -3.5 : 0.27008820585226917
python_maths.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4