64.5.27 problem 27

Internal problem ID [13269]
Book : Differential Equations by Shepley L. Ross. Third edition. John Willey. New Delhi. 2004.
Section : Chapter 2, section 2.3 (Linear equations). Exercises page 56
Problem number : 27
Date solved : Monday, March 31, 2025 at 07:44:39 AM
CAS classification : [[_linear, `class A`]]

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

With initial conditions

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

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