scipy.integrate.
fixed_quad#
- scipy.integrate.fixed_quad(func, a, b, args=(), n=5)[source]#
使用固定階高斯求積法計算定積分。
使用階數 n 的高斯求積法,積分從 a 到 b 的 func。
- 參數:
- funccallable
要積分的 Python 函數或方法(必須接受向量輸入)。如果積分向量值函數,則返回的陣列必須具有形狀
(..., len(x))
。- afloat
積分下限。
- bfloat
積分上限。
- argstuple, optional
要傳遞給函數的額外參數(如果有的話)。
- nint, optional
求積積分的階數。預設值為 5。
- 返回:
- valfloat
高斯求積法對積分的近似值
- noneNone
靜態返回的 None 值
參見
範例
>>> from scipy import integrate >>> import numpy as np >>> f = lambda x: x**8 >>> integrate.fixed_quad(f, 0.0, 1.0, n=4) (0.1110884353741496, None) >>> integrate.fixed_quad(f, 0.0, 1.0, n=5) (0.11111111111111102, None) >>> print(1/9.0) # analytical result 0.1111111111111111
>>> integrate.fixed_quad(np.cos, 0.0, np.pi/2, n=4) (0.9999999771971152, None) >>> integrate.fixed_quad(np.cos, 0.0, np.pi/2, n=5) (1.000000000039565, None) >>> np.sin(np.pi/2)-np.sin(0) # analytical result 1.0