与多个数组集成功能的问题

发布于 2025-01-28 13:33:33 字数 1197 浏览 3 评论 0原文

我需要集成一个很长的功能。该函数包含几个数组,我没有成功整合它。 我需要将其集成到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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩发小公举 2025-02-04 13:33:33

如果您要逐步进行此部分:

Tau,err=quad(function1(teta1,w[n],f[n],Mag_Gam[n]),0,80,args=(1,)) #Integration on teta1

您会注意到您正在提供Quad(我认为这是scipy.integrate.quad)而不是可呼叫功能,但是已经计算出的值数组可以使用!

相反,请尝试传递函数对象(并且实际上还记得在输出数组中设置值,而不是用单个数字覆盖它们):

Tau[n], err[n] = quad(function1, 0,80,args=(w[n],f[n],Mag_Gam[n]))

If you were to do this part step-by-step:

Tau,err=quad(function1(teta1,w[n],f[n],Mag_Gam[n]),0,80,args=(1,)) #Integration on teta1

You'd notice that you're giving quad (which I assume is scipy.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):

Tau[n], err[n] = quad(function1, 0,80,args=(w[n],f[n],Mag_Gam[n]))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文