与多个数组集成功能的问题
我需要集成一个很长的功能。该函数包含几个数组,我没有成功整合它。 我需要将其集成到TETA1(80)上,但它也包含W(22,),F(22,),GAM_MAG(22,)。我试图分解它,但我不确定它是否好。
这是我的功能:
def function1(teta1,w,f,Mag_Gam):
Zp1=i*w*ms1*(1-(1+i*Nu)*np.sin(teta1)**4*(f/fc1)**2)
a1=1
b1=Zp1
c1=0
d1=1
ac=np.cosh(Mag_Gam*d*np.cos(teta1))
bc=Zc*np.sinh(Mag_Gam*d*np.cos(teta1))/np.cos(teta1)
cc=np.sinh(Mag_Gam*d*np.cos(teta1))/Zc*np.cos(teta1)
dc=np.cosh(Mag_Gam*d*np.cos(teta1))
Zp2=i*w*ms2*(1-(1+i*Nu)*np.sin(teta1)**4*(f/fc2)**2)#B1/(i*w)*(k0**4*np.sin(teta)**4-kb1**4)
a2=1
b2=Zp2
c2=0
d2=1
at=a1*ac+b1*cc
bt=a1*bc+b1*dc
ct=c1*ac+d1*cc
dt=c1*bc+d1*dc
aT=at*a2+bt*c2
bT=at*b2+bt*d2
cT=ct*a2+dt*c2
dT=ct*b2+d2*dt
T=np.array([[aT,bT],[cT,dT]])
return 4*abs(T[0,0]+T[0,1]/Zc+Zc*T[1,0]+Zc*T[1,1]/Zc)**(-2)
在这里集成:
Tau=np.zeros(len(f))
err=np.zeros(len(f))
for n in range(len(f)):
Tau,err=quad(function1(teta1,w[n],f[n],Mag_Gam[n]),0,80,args=(1,)) #Integration on teta1
TL=10*np.log10(1/Tau)
这是错误消息:
I need to integrate a very long function. The function contains several array and I don't succeed to integrate it.
I need to integrate it on teta1 (80,) but it contains also w (22,),f (22,),Gam_Mag (22,). I tried to decompose it but I'm not sure if it's good or not.
Here is my function:
def function1(teta1,w,f,Mag_Gam):
Zp1=i*w*ms1*(1-(1+i*Nu)*np.sin(teta1)**4*(f/fc1)**2)
a1=1
b1=Zp1
c1=0
d1=1
ac=np.cosh(Mag_Gam*d*np.cos(teta1))
bc=Zc*np.sinh(Mag_Gam*d*np.cos(teta1))/np.cos(teta1)
cc=np.sinh(Mag_Gam*d*np.cos(teta1))/Zc*np.cos(teta1)
dc=np.cosh(Mag_Gam*d*np.cos(teta1))
Zp2=i*w*ms2*(1-(1+i*Nu)*np.sin(teta1)**4*(f/fc2)**2)#B1/(i*w)*(k0**4*np.sin(teta)**4-kb1**4)
a2=1
b2=Zp2
c2=0
d2=1
at=a1*ac+b1*cc
bt=a1*bc+b1*dc
ct=c1*ac+d1*cc
dt=c1*bc+d1*dc
aT=at*a2+bt*c2
bT=at*b2+bt*d2
cT=ct*a2+dt*c2
dT=ct*b2+d2*dt
T=np.array([[aT,bT],[cT,dT]])
return 4*abs(T[0,0]+T[0,1]/Zc+Zc*T[1,0]+Zc*T[1,1]/Zc)**(-2)
Here the integration:
Tau=np.zeros(len(f))
err=np.zeros(len(f))
for n in range(len(f)):
Tau,err=quad(function1(teta1,w[n],f[n],Mag_Gam[n]),0,80,args=(1,)) #Integration on teta1
TL=10*np.log10(1/Tau)
And here is the error message:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您要逐步进行此部分:
您会注意到您正在提供
Quad
(我认为这是scipy.integrate.quad
)而不是可呼叫功能,但是已经计算出的值数组可以使用!相反,请尝试传递函数对象(并且实际上还记得在输出数组中设置值,而不是用单个数字覆盖它们):
If you were to do this part step-by-step:
You'd notice that you're giving
quad
(which I assume isscipy.integrate.quad
) not a callable function, but an array of already computed values to work with!Try this, instead, passing the function object (and also actually remembering to set values within your output arrays, instead of overwriting them with single numbers):