67.4.27 problem Problem 4(c)

Internal problem ID [14000]
Book : APPLIED DIFFERENTIAL EQUATIONS The Primary Course by Vladimir A. Dobrushkin. CRC Press 2015
Section : Chapter 5.6 Laplace transform. Nonhomogeneous equations. Problems page 368
Problem number : Problem 4(c)
Date solved : Monday, March 31, 2025 at 08:21:25 AM
CAS classification : [[_2nd_order, _linear, _nonhomogeneous]]

\begin{align*} y^{\prime \prime }+3 y^{\prime }+2 y&=\left \{\begin {array}{cc} 1 & 0\le t <2 \\ -1 & 2\le t \end {array}\right . \end{align*}

Using Laplace method With initial conditions

\begin{align*} y \left (0\right )&=0\\ y^{\prime }\left (0\right )&=0 \end{align*}

Maple. Time used: 0.163 (sec). Leaf size: 49
ode:=diff(diff(y(t),t),t)+3*diff(y(t),t)+2*y(t) = piecewise(0 <= t and t < 2,1,2 <= t,-1); 
ic:=y(0) = 0, D(y)(0) = 0; 
dsolve([ode,ic],y(t),method='laplace');
 
\[ y = \frac {\left (\left \{\begin {array}{cc} \left ({\mathrm e}^{-t}-1\right )^{2} & t <2 \\ -1+4 \,{\mathrm e}^{2-t}-2 \,{\mathrm e}^{4-2 t}-2 \,{\mathrm e}^{-t}+{\mathrm e}^{-2 t} & 2\le t \end {array}\right .\right )}{2} \]
Mathematica. Time used: 0.044 (sec). Leaf size: 68
ode=D[y[t],{t,2}]+3*D[y[t],t]+2*y[t]==Piecewise[{{1,0<=t<2},{-1,t>=2}}]; 
ic={y[0]==0,Derivative[1][y][0] ==0}; 
DSolve[{ode,ic},y[t],t,IncludeSingularSolutions->True]
 
\[ y(t)\to \begin {array}{cc} \{ & \begin {array}{cc} 0 & t\leq 0 \\ \frac {1}{2} e^{-2 t} \left (-1+e^t\right )^2 & 0<t\leq 2 \\ -\frac {1}{2} e^{-2 t} \left (-1+2 e^4+2 e^t+e^{2 t}-4 e^{t+2}\right ) & \text {True} \\ \end {array} \\ \end {array} \]
Sympy
from sympy import * 
t = symbols("t") 
y = Function("y") 
ode = Eq(-Piecewise((1, (t >= 0) & (t < 2)), (-1, t >= 2)) + 2*y(t) + 3*Derivative(y(t), t) + Derivative(y(t), (t, 2)),0) 
ics = {y(0): 0, Subs(Derivative(y(t), t), t, 0): 0} 
dsolve(ode,func=y(t),ics=ics)