74.5.38 problem 42

Internal problem ID [15931]
Book : INTRODUCTORY DIFFERENTIAL EQUATIONS. Martha L. Abell, James P. Braselton. Fourth edition 2014. ElScAe. 2014
Section : Chapter 2. First Order Equations. Exercises 2.3, page 49
Problem number : 42
Date solved : Monday, March 31, 2025 at 02:13:43 PM
CAS classification : [[_linear, `class A`]]

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

With initial conditions

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

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