76.3.22 problem 27

Internal problem ID [17314]
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 : Thursday, March 13, 2025 at 09:25:42 AM
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: 1.303 (sec). Leaf size: 38
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 = \frac {\left (\left \{\begin {array}{cc} 0 & t <0 \\ 1-{\mathrm e}^{-2 t} & t <1 \\ {\mathrm e}^{2-2 t}-{\mathrm e}^{-2 t} & 1\le t \end {array}\right .\right )}{2} \]
Mathematica. Time used: 0.051 (sec). Leaf size: 48
ode=D[y[t],t]+2*y[t]==Piecewise[{{1,0<=t<=1},{0,t>1}}]; 
ic={}; 
DSolve[{ode,ic},y[t],t,IncludeSingularSolutions->True]
 
\[ y(t)\to e^{-2 t} \left (\left ( \begin {array}{cc} \{ & \begin {array}{cc} \frac {1}{2} \left (-1+e^2\right ) & t>1 \\ \frac {1}{2} \left (-1+e^{2 t}\right ) & 0<t\leq 1 \\ \end {array} \\ \end {array} \right )+c_1\right ) \]
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 ] \]