Python3 math.gamma() 方法 -求伽馬函數(shù)值

2023-04-25 13:48 更新

Python math 模塊  math 模塊


描述

 math.gamma(x) 方法返回 x 處的伽瑪函數(shù)(Gamma 函數(shù))。

伽瑪函數(shù),也叫歐拉第二積分,是階乘函數(shù)在實數(shù)與復數(shù)上擴展的一類函數(shù)。

要查找數(shù)字的對數(shù)伽瑪值,請使用 math.lgamma() 方法。

 本函數(shù)只在python3.2以上有效!


語法

math.gamma() 方法語法如下:

math.gamma(x)

參數(shù)說明:

  • x -- 必需,數(shù)字。如果數(shù)字是負整數(shù),則返回 ValueError。 如果不是數(shù)字,則返回 TypeError。

返回值

一個浮點值,表示表示 x 處的伽瑪函數(shù)。


實例

以下實例計算不同數(shù)的伽瑪函數(shù):

# 導入 math 包
import math

# 計算不同數(shù)的伽瑪函數(shù)
print(math.gamma(-0.1))
print(math.gamma(8))
print(math.gamma(1.2))
print(math.gamma(80))
print(math.gamma(-0.55))

輸出結果:

-10.686287021193193
5040.0
0.9181687423997604
8.946182130782976e+116
-3.578429819277059

Python math 模塊  math 模塊


以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號