python 中的积分: y(t,E)=-A+2A*Integral [g(t,tau)*f(Ea)]dEa

问题描述 投票:0回答:1

我需要进行图中写的积分:

enter image description here

我想针对给定的 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)
python math numerical-integration
1个回答
0
投票

我认为您可以安全地忽略该警告。积分可能在某个时刻发散,并且您收到的警告表明迭代次数不足以找到收敛的解决方案。如果打印误差 (

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)$')

© www.soinside.com 2019 - 2024. All rights reserved.