0

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

SM KIM
  • 7
  • 2
  • The code as shown works fine for me and give `y` as a function of `t`. substituting `y.subs(t, 1.0)` gives `-0.00623772329557204` as expected so what do you mean by "I couldn't get the result"? – Oscar Benjamin Dec 04 '22 at 12:02
  • I chaged integrate into Intergral and could get the same result which I calculated using by Ti Nspire software!!! – SM KIM Dec 04 '22 at 15:32

1 Answers1

1

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)
smichr
  • 16,948
  • 2
  • 27
  • 34
  • I could got the solution y(1)=-0.006237723 as your advisor. Additionally, how can I get the whole response like I got the solution using by Ti Nspire? In my Jupyter notebook, when I use Intergral fuction, the result is not same as Ti Nspire's one. In which, the integral sign is stiil remain. – SM KIM Dec 04 '22 at 15:27
  • I don't understand the output from Ti. The `y0` when using `Integral` has integral sign so I am not sure what you are seeking. – smichr Dec 05 '22 at 05:30
  • This is the output from the Ti. [Ti output](https://i.stack.imgur.com/o4mUF.png) You can see the result on the sencond line from the bottom. – SM KIM Dec 05 '22 at 19:43
  • But Sympy doesn't retuen the same result response like this though when re result t=1 sec is same. [sympy rerult](https://i.stack.imgur.com/mPR2E.png) – SM KIM Dec 05 '22 at 19:57
  • SymPy needed a little help to do the symbolic integral. See updated answer. – smichr Dec 05 '22 at 20:30