64.6.22 problem 22

Internal problem ID [13293]
Book : Differential Equations by Shepley L. Ross. Third edition. John Willey. New Delhi. 2004.
Section : Chapter 2, Miscellaneous Review. Exercises page 60
Problem number : 22
Date solved : Wednesday, March 05, 2025 at 09:34:58 PM
CAS classification : [[_linear, `class A`]]

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

With initial conditions

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

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