积分在科学和工程应用中具有许多重要的应用,本文利用 SciPy
解决积分相关问题。
知识点描述:具有函数表达式的被积函数求积分。
问题描述:求解积分
∫
−
1
1
e
−
x
2
d
x
\int _{-1}^1 e^{-x^2}dx
∫−11e−x2dx,请从以下选项中选出你认为正确的答案:
A.
from scipy import integrate import numpy as np def func(x): return np.exp(-x**2) val, err = integrate.quad(func(x), -1, 1) print(val)
B.
from scipy import integrate import numpy as np def func(x, a=-1, b=1): return np.exp(-x**2) val, err = integrate.quad(func) print(val)
C.
from scipy import integrate import numpy as np def func(x, a=-1, b=1): return np.exp(-x**2) val, err = integrate.quad(func(x)) print(val)
D.
from scipy import integrate import numpy as np def func(x): return np.exp(-x**2) val, err = integrate.quad(func, -1, 1) print(val)
正确答案: D
知识点描述:函数表达式未知的积分求解。
问题描述:假设仅知道某一函数其中一些点的值,并不知道其具体函数表达式,求解其积分,请从以下选项中选出你认为正确的答案:
A.
from scipy import integrate import numpy as np func = lambda x: np.sqrt(x) x = np.linspace(0, 2, 25) y = func(x) val = integrate.trapz(y, 0, 2) print(val)
B.
from scipy import integrate import numpy as np func = lambda x: np.sqrt(x) x = np.linspace(0, 2, 25) y = func(x) val = integrate.trapz(y, x) print(val)
C.
from scipy import integrate import numpy as np func = lambda x: np.sqrt(x) x = np.linspace(0, 2, 25) y = func(x) val, err = integrate.quad(y, 0, 2) print(val)
D.
from scipy import integrate import numpy as np func = lambda x: np.sqrt(x) x = np.linspace(0, 2, 25) y = func(x) val, err = integrate.quad(y, x) print(val)
正确答案: B
https://codechina.csdn.net/LOVEmy134611/python_problem