python - python中的积分:y(t,E)=-A+2A*Integral [g(t,tau)*f(Ea)]dEa
问题描述
我需要进行图中写的积分:
我想为 E 的给定值绘制 y(t,E)。在我的代码中,我收到以下消息:“在 double_scalars 中遇到除以零”
我不明白在集成过程中为什么会出现“除以”?什么是更好的代码来完成这项工作?
我的代码:
from scipy.integrate import quad
import numpy as np
def integrand(Ea,A,t,E,tau0,n,alpha,mu,sig):
tau=tau0*np.exp(-np.power(E/Ea,alpha));
g=1-np.exp(-np.power((t/tau),n));
f=np.exp(-np.power(Ea - mu, 2.) / (2 * np.power(sig, 2.)));
return -A+2*A*g*f
#
A=25;
t=1e-6; #Calculating for one t value. For plotting, t would be an array.
E=1;
tau0=0.3*1e-6;
n=2;
alpha=5
mu=2;
sig=0.3;
Y = quad(integrand, 0, np.inf, args=(A,t,E,tau0,n,alpha,mu,sig))
print(Y)
解决方案
我认为您可以放心地忽略该警告。积分可能在某个时候发散,并且您收到的警告表明迭代次数不足以找到收敛的解决方案。如果您打印错误 ( y[1]
),您将看到它与积分的绝对值 ( ) 相比非常小y[0]
。积分与时间的相关性可以计算如下
time = np.logspace(-8, -5, 100)
Ylist = []
for t in time:
Y = quad(integrand, 0, np.inf, args=(A,t,E,tau0,n,alpha,mu,sig))
Ylist.append(Y[0])
plt.semilogx(time, Ylist, '-kx')
plt.xlabel('Time (log)')
plt.ylabel(r'$y(t, E)$')
推荐阅读
- jquery - 我只想在按钮单击时显示隐藏的移动格式?
- c# - 为什么我不能在 CudaFy 库的 c# 代码中设置断点?
- apache - 防止Apache2.2 web服务器中的暴力密码攻击
- c# - 在 WPF 中找不到附加属性
- mysql - 没有默认值错误!拉拉维尔
- c - 指向数组转换的数组指针 - C/C++ 初学者
- python-3.x - HSV OpenCv 颜色范围
- python - 熊猫如何阅读子标题
- sql - 如何根据入职日期计算特定日期的可用员工总数?
- java - Spring中的ImportSelector和ImportBeanDefinitionRegistar有什么区别?