76.3.22 problem 27

Internal problem ID [17322]
Book : Differential equations. An introduction to modern methods and applications. James Brannan, William E. Boyce. Third edition. Wiley 2015
Section : Chapter 2. First order differential equations. Section 2.4 (Differences between linear and nonlinear equations). Problems at page 79
Problem number : 27
Date solved : Monday, March 31, 2025 at 03:52:39 PM
CAS classification : [[_linear, `class A`]]

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

With initial conditions

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

Maple. Time used: 0.088 (sec). Leaf size: 32
ode:=diff(y(t),t)+2*y(t) = piecewise(0 <= t and t <= 1,1,1 < t,0); 
ic:=y(0) = 0; 
dsolve([ode,ic],y(t), singsol=all);
 
\[ y = \left \{\begin {array}{cc} 0 & t <0 \\ \frac {1}{2}-\frac {{\mathrm e}^{-2 t}}{2} & t <1 \\ \sinh \left (1\right ) {\mathrm e}^{1-2 t} & 1\le t \end {array}\right . \]
Mathematica. Time used: 0.095 (sec). Leaf size: 46
ode=D[y[t],t]+2*y[t]==Piecewise[{{1,0<=t<=1},{0,t>1}}]; 
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 \\ \frac {1}{2}-\frac {e^{-2 t}}{2} & 0<t\leq 1 \\ \frac {1}{2} e^{-2 t} \left (-1+e^2\right ) & \text {True} \\ \end {array} \\ \end {array} \]
Sympy. Time used: 0.398 (sec). Leaf size: 51
from sympy import * 
t = symbols("t") 
y = Function("y") 
ode = Eq(-Piecewise((1, (t >= 0) & (t <= 1)), (0, t > 1)) + 2*y(t) + Derivative(y(t), t),0) 
ics = {} 
dsolve(ode,func=y(t),ics=ics)
 
\[ \left [ y{\left (t \right )} = \begin {cases} \frac {C_{1}}{e^{2 t} + 1} + \frac {e^{2}}{2 e^{2 t} + 2} & \text {for}\: t > 1 \\\text {NaN} & \text {otherwise} \end {cases}, \ y{\left (t \right )} = \begin {cases} \frac {C_{1}}{e^{2 t} + 1} + \frac {e^{2 t}}{2 e^{2 t} + 2} & \text {for}\: t \leq 1 \wedge t > 0 \\\text {NaN} & \text {otherwise} \end {cases}\right ] \]