首页 > 解决方案 > 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)

标签: pythonmathintegration

解决方案


我认为您可以放心地忽略该警告。积分可能在某个时候发散,并且您收到的警告表明迭代次数不足以找到收敛的解决方案。如果您打印错误 ( 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)$')

在此处输入图像描述


推荐阅读