44.6.38 problem 38

Internal problem ID [7182]
Book : A First Course in Differential Equations with Modeling Applications by Dennis G. Zill. 12 ed. Metric version. 2024. Cengage learning.
Section : Chapter 2. First order differential equations. Section 2.3 Linear equations. Exercises 2.3 at page 63
Problem number : 38
Date solved : Sunday, March 30, 2025 at 11:50:26 AM
CAS classification : [[_linear, `class A`]]

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

With initial conditions

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

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