如何通过python进行卷积积分(Duhamel积分)?

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

嗨~我正在研究结构动力学。 我想编写一个关于杜哈梅尔积分的代码,这是一种卷积积分。

如果初始条件为 y(0)=0 且 y'(0)=0, 杜哈梅尔积分就是这样。 enter image description here

使用Ti Nspire 我用 Ti Npire 软件解决了这个问题。结果就是这样。 enter image description here

t=1 时的响应(y)为 -0.006238

使用python(sympy) 我尝试使用Python(Jupyter Notebook)来解决这个问题。 但我无法解决问题。

我是这样写代码的。

from sympy import *

t, tau=symbols('t, tau')

m=6938.78
k=379259
wn=sqrt(k/m)
wd=wn*sqrt(1-0.05**2)

eq1=(900*sin(5.3*tau))
eq2=exp(-0.05*wn*(t-tau))
eq3=sin(wd*(t-tau))

y0=1/(m*wd)*integrate(eq1*eq2*eq3,(tau,0,t))
y0

但我无法得到结果。 enter image description here

还有其他方法可以解决这个问题吗?

enter image description here

python response sympy convolution symbolic-integration
1个回答
1
投票

使用未计算的积分,然后代入一个值

t
并使用
doit
方法:

...
>>> y0=1/(m*wd)*Integral(eq1*eq2*eq3,(tau,0,t))
>>> y0.subs(t,1).doit()
-0.00623772329557205

要在替换之前查看符号结果

t=1
,您需要通过扩展被积函数来帮助 SymPy;为了简单起见,我还对浮点数进行了评估,使其仅显示 3 位数字:

>>> integrate((eq1*eq2*eq3).expand(),(tau,0,t)).simplify().replace(
... lambda x:x.is_Float, lambda x: x.n(3))
245.0*sin(5.3*t) - 36.1*cos(5.3*t) - 174.0*exp(-0.37*t)*sin(7.38*t) + 36.1*exp(-0.37*t)*cos(7.38*t)
© www.soinside.com 2019 - 2024. All rights reserved.