8.1.17 problem 17

Internal problem ID [2488]
Book : Differential equations and their applications, 4th ed., M. Braun
Section : Chapter 1. First order differential equations. Section 1.2. Linear equations. Excercises page 9
Problem number : 17
Date solved : Tuesday, September 30, 2025 at 05:36:53 AM
CAS classification : [[_linear, `class A`]]

\begin{align*} y^{\prime }+y&=\left \{\begin {array}{cc} 2 & 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.080 (sec). Leaf size: 38
ode:=diff(y(t),t)+y(t) = piecewise(0 <= t and t <= 1,2,1 < t,0); 
ic:=[y(0) = 0]; 
dsolve([ode,op(ic)],y(t), singsol=all);
 
\[ y = \left \{\begin {array}{cc} 0 & t <0 \\ 2-2 \,{\mathrm e}^{-t} & t <1 \\ 2 \,{\mathrm e}^{1-t}-2 \,{\mathrm e}^{-t} & 1\le t \end {array}\right . \]
Mathematica. Time used: 0.038 (sec). Leaf size: 40
ode=D[y[t],t]+y[t]==Piecewise[{{2,0<=t<=2},{0,t>1}}]; 
ic={y[0]==0}; 
DSolve[{ode,ic},y[t],t,IncludeSingularSolutions->True]
 
\begin{align*} y(t)&\to \begin {array}{cc} \{ & \begin {array}{cc} 0 & t\leq 0 \\ 2-2 e^{-t} & 0<t\leq 2 \\ 2 e^{-t} \left (-1+e^2\right ) & \text {True} \\ \end {array} \\ \end {array} \end{align*}
Sympy. Time used: 0.172 (sec). Leaf size: 17
from sympy import * 
t = symbols("t") 
y = Function("y") 
ode = Eq(-Piecewise((2, (t >= 0) & (t <= 2)), (0, t > 1)) + y(t) + Derivative(y(t), (t, 2)),0) 
ics = {y(0): 0} 
dsolve(ode,func=y(t),ics=ics)
 
\[ y{\left (t \right )} = C_{1} \sin {\left (t \right )} + \begin {cases} 2 & \text {for}\: t \geq 0 \wedge t \leq 2 \\0 & \text {for}\: t > 2 \\\text {NaN} & \text {otherwise} \end {cases} - 2 \cos {\left (t \right )} \]