20.22.17 problem Problem 46 part b

Internal problem ID [3972]
Book : Differential equations and linear algebra, Stephen W. Goode and Scott A Annin. Fourth edition, 2015
Section : Chapter 10, The Laplace Transform and Some Elementary Applications. Exercises for 10.7. page 704
Problem number : Problem 46 part b
Date solved : Sunday, March 30, 2025 at 02:13:23 AM
CAS classification : [[_linear, `class A`]]

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

With initial conditions

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

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