专门做餐饮空间设计的网站,做网站注册的商标类别,WordPress 远程发布,百度游戏官网先上一个二重积分计算#xff0c;来自2022年考研数学第二题 进行计算前先在终端下载 scipy包
pip install scipy
在脚本中先导入所需要的模块
import scipy.integrate as spi
定义函数f(x, y) #xff0c;所得值返回
def f(x, y): return y / (1 x**3)**0.5
定义… 先上一个二重积分计算来自2022年考研数学第二题 进行计算前先在终端下载 scipy包
pip install scipy
在脚本中先导入所需要的模块
import scipy.integrate as spi
定义函数f(x, y) 所得值返回
def f(x, y): return y / (1 x**3)**0.5
定义函数x_lower(y)和x_upper(y)返回值是在给定的y值下x的积分上下限
def x_lower(y): return y def x_upper(y): return 2
设置y的积分上下限
y_lower 0
y_upper 2
使用SciPy的dblquad函数进行双重积分。首先对x在给定的y值下从x_lower到x_upperx进行积分然后在y_lower到y_upper对y进行积分
result, error spi.dblquad(f, y_lower, y_upper, x_lower, x_upper)
最后打印计算积分所得结果和估计误差
print(f计算结果{result}, 估计误差{error})
计算结果如下原答案为
计算结果0.6666666666666667, 估计误差3.034575198616355e-10
全部代码
import scipy.integrate as spi def f(x, y): return y / (1 x**3)**0.5
def x_lower(y): return y
def x_upper(y): return 2 y_lower 0
y_upper 2 result, error spi.dblquad(f, y_lower, y_upper, x_lower, x_upper)
print(f计算结果{result}, 估计误差{error}) 第二题是2022年考研数学第13题 使用SciPy的quad函数计算定积分quad函数接受三个参数被积函数、积分下限和积分上限题目给出从0到1定积分。
integral_value, error spi.quad(integrand, 0, 1)
计算结果如下标准答案为
计算结果4.83680估计误差5.12771e-13
全部代码
import scipy.integrate as spi def integrand(x): return (2*x 3) / (x**2 - x 1) integral_value, error spi.quad(integrand, 0, 1) print(f计算结果{integral_value:.5f}估计误差{error:.5e})
第三题是2021年考研数学第11题 使用SciPy的quad函数计算从0到100的定积分,计算函数integrand在0到100区间上的积分
integral_value, error spi.quad(integrand, 0, 100)
原题中的积分是从负无穷到正无穷且函数关于y轴对称所以将原积分拆分为两部分并从0到正无穷积分然后结果乘以2。
answer 2 * integral_value
计算结果如下标准答案为
积分的数值结果为0.91024估计误差为9.10711e-10
完整代码
import scipy.integrate as spi def integrand(x): return x * 3**(-x**2) integral_value, error spi.quad(integrand, 0, 100)
answer 2 * integral_value print(f积分的数值结果为{answer:.5f}估计误差为{error:.5e})