pythonresponsesympyconvolutionsymbolic-integration

How to convolution integration(Duhamel Integration) by python?


Hi~ I'm studying about structural dynamics. I want to make a code about Duhamel Integration which is kind of Convoution Integration.

If the initial conditions are y(0)=0 and y'(0)=0, Duhamel Integration is like this. enter image description here

Using Ti Nspire I solved this problem with my Ti Npire softwere. The result is like that. enter image description here

Its response(y) of t=1 is -0.006238

Using python(sympy) I tried to solve this problem using by Python(Jupyter Notebook). But I couldn't solve the problem.

I wrote the code like this.

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

But I couldn't get the result. enter image description here

Is there other way to solve this problem?

enter image description here


Solution

  • Use the unevaluated Integral and then substitute in a value for t and use the doit method:

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

    To see the symbolic result before substituting t=1 you need to help SymPy a little by expanding your integrand; I also evaluate floats to show only 3 digits from sake of simplicity:

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