with 1.7.1, I get simpler results (no unsolved integrals) :

>>> y=Function("y")
>>> t=Symbol("t")
>>> g=8*(Heaviside(t)-Heaviside(t-5))+40*Heaviside(t-5)
>>> eq=Eq(y(t).diff(t,2)+4*y(t),g)
>>> dsolve(eq,y(t))
Eq(y(t), C1*sin(2*t) + C2*cos(2*t) + 4*sin(t)**2*Heaviside(t) + 16*sin(t)*sin(t 
- 10)*Heaviside(t - 5) - 8*cos(10)*Heaviside(t - 5) + 8*Heaviside(t - 5))
>>> dsolve(eq,y(t),ics={y(0):0,y(t).diff(t).subs(t,0):0})
Eq(y(t), 4*sin(t)**2*Heaviside(t) + 16*sin(t)*sin(t - 10)*Heaviside(t - 5) - 
8*cos(10)*Heaviside(t - 5) + 8*Heaviside(t - 5))

And the result is consonant with whatever Mathematica returns…

HTH,
Le mercredi 13 janvier 2021 à 19:59:23 UTC+1, Oscar a écrit :

> I haven't used sympy's Laplace transform code but I can tell you that
> dsolve is able to solve the differential equation:
>
> In [14]: y = Function('y')
>
> In [15]: t = Symbol('t')
>
> In [16]: g = 8*t*(Heaviside(t) - Heaviside(t-5)) + 40*Heaviside(t-5)
>
> In [17]: eq = Eq(y(t).diff(t, 2) + 4*y(t), g)
>
> In [18]: str(eq)
> Out[18]: 'Eq(4*y(t) + Derivative(y(t), (t, 2)), 8*t*(Heaviside(t) -
> Heaviside(t - 5)) + 40*Heaviside(t - 5))'
>
> In [19]: str(dsolve(eq))
> Out[19]: 'Eq(y(t), 2*(t*Heaviside(t) + 5*Heaviside(t - 5))*cos(2*t)**2
> + (C1 - 10*cos(10)*Heaviside(t - 5) +
> 4*Integral(t*sin(2*t)*Heaviside(t - 5), t))*cos(2*t) +
> 2*(t*Heaviside(t) - t*Heaviside(t - 5) + 5*Heaviside(t -
> 5))*sin(2*t)**2 + (C2 - cos(2*t)*Heaviside(t - 5) - Heaviside(t) +
> cos(10)*Heaviside(t - 5))*sin(2*t))'
>
> There is an unevaluated integral in there and it's quite slow because
> of computing the integrals involved so there can be improvements to
> made to the integration routines here.
>
> Not having used sympy's laplace transforms before I'm not sure how
> they would be used for a case like this:
>
> In [24]: s = Symbol('s')
>
> In [25]: str(laplace_transform(eq.lhs - eq.rhs, t, s))
> Out[25]: '(4*LaplaceTransform(y(t), t, s) +
> LaplaceTransform(Derivative(y(t), (t, 2)), t, s) - 40*exp(-5*s)/s +
> 8*(5*s - exp(5*s) + 1)*exp(-5*s)/s**2, 0, True)'
>
> I guess that `LaplaceTransform(Derivative(y(t), (t, 2)), t, s)` is an
> unevaluated Laplace transform of the derivative. How exactly does
> Matlab represent that?
>
>
> Oscar
>
> On Wed, 13 Jan 2021 at 18:46, Staffan Lundberg
> <[email protected]> wrote:
> >
> >
> > I am working with a project to replace Matlab with Python, in a calculus 
> course. Explicitly, following problem is solved in Matlab. It is an 
> inhomogenous IVP with constant coefficients together with relevant IC's. In 
> Matlab Code: Dy=diff(y(t),t); D2y=diff(Dy,t); 
> g=8*t*(heaviside(t)-heaviside(t-5))+40*heaviside(t-5); ode=D2y+4*y-g ==0; 
> My goal is to Laplace transform the equation, obtain a solution in 
> frequency domain, and finally transform it back to time domain, obtaining 
> the final solution. This procedure is successfully done by Matlab.
> >
> > I address this issue to the developer team. Will it, in future releases 
> of SymPy, be possible to solve this problem in Python/SymPy?
> >
> > --
> > You received this message because you are subscribed to the Google 
> Groups "sympy" group.
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to [email protected].
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/10568891-8a24-43aa-8f93-e1a6b7de72e6n%40googlegroups.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/deeb7271-d42b-4f33-b043-048b65a16459n%40googlegroups.com.

Reply via email to