- SciPy 教程
- SciPy - 主頁
- SciPy - 簡介
- SciPy - 環境設定
- SciPy - 基本功能
- SciPy - 叢集
- SciPy - 常量
- SciPy - FFTpack
- SciPy - 整合
- SciPy - 插值
- SciPy - 輸入和輸出
- SciPy - 線性代數
- SciPy - N維影像
- SciPy - 最佳化
- SciPy - 統計
- SciPy - CSGraph
- SciPy - 空間
- SciPy - ODR
- SciPy - 特殊包
- SciPy 有用資源
- SciPy - 參考
- SciPy - 快速指南
- SciPy - 有用資源
- SciPy - 討論
SciPy - integrate.nquad() 方法
SciPy integrate.nquad() 方法用於查詢多變數積分。在建立程式時,必須將模組指定為 scipy.integrate。
語法
以下是 SciPy integrate.nquad() 方法的語法:
scipy.integrate.nquad(custom_func, [[0, 1], [0, 1]])
引數
此方法接受以下引數:
- custom_func:此引數用於積分工作,其中它執行積分(上限和下限)的任務。
- [0, 1]:此引數用於定義上限範圍。
- [1, 0]:此引數用於定義下限範圍。
- args = (a, b):如果使用者希望更多變數執行積分工作,則此引數是可選的。
返回值
該方法返回浮點型結果積分值。
示例 1
以下是 SciPy integrate.nquad() 方法的基本示例,說明了在兩個變數上進行積分。
import scipy.integrate
def integrand(x, y):
return x**2 + y**2
# perform the nquad()
res, _ = scipy.integrate.nquad(integrand, [[0, 1], [0, 1]])
print("The double integral result is ", res)
輸出
上述程式碼生成以下輸出:
The double integral result is 0.6666666666666669
示例 2
在此,我們對三個變數(x、y 和 z)執行積分操作。
import scipy.integrate
def integrand(x, y, z):
return x + y + z
# perform the nquad()
res, _ = scipy.integrate.nquad(integrand, [[0, 1], [0, 1], [0, 1]])
print("The triple integral result is ", res)
輸出
上述程式碼生成以下輸出:
The triple integral result is 1.5
示例 3
在程式下方使用多個變數(x、y、a 和 b)計算積分結果。
import scipy.integrate
def integrand(x, y, a, b):
return a * x + b * y
a = 2
b = 3
# perform the nquad()
res, _ = scipy.integrate.nquad(integrand, [[0, 1], [0, 1]], args=(a, b))
# display the result
print("The double integral with parameter result is ", res)
輸出
上述程式碼生成以下輸出:
The double integral with parameter result is 2.5
scipy_reference.htm
廣告