20.3.21 problem Problem 21

Internal problem ID [3630]
Book : Differential equations and linear algebra, Stephen W. Goode and Scott A Annin. Fourth edition, 2015
Section : Chapter 1, First-Order Differential Equations. Section 1.6, First-Order Linear Differential Equations. page 59
Problem number : Problem 21
Date solved : Tuesday, March 04, 2025 at 04:55:18 PM
CAS classification : [[_linear, `class A`]]

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

With initial conditions

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

Maple. Time used: 0.199 (sec). Leaf size: 31
ode:=diff(y(x),x)-2*y(x) = piecewise(x < 1,1-x,1 <= x,0); 
ic:=y(0) = 1; 
dsolve([ode,ic],y(x), singsol=all);
 
\[ y \left (x \right ) = \frac {5 \,{\mathrm e}^{2 x}}{4}+\frac {\left (\left \{\begin {array}{cc} 2 x -1 & x <1 \\ {\mathrm e}^{2 x -2} & 1\le x \end {array}\right .\right )}{4} \]
Mathematica. Time used: 0.093 (sec). Leaf size: 45
ode=D[y[x],x] - 2*y[x] == Piecewise[{{1-x, x < 1}, {0, x >= 1}}]; 
ic={y[0]==1}; 
DSolve[{ode,ic},y[x],x,IncludeSingularSolutions->True]
 
\[ y(x)\to \begin {array}{cc} \{ & \begin {array}{cc} \frac {1}{4} \left (2 x+5 e^{2 x}-1\right ) & x\leq 1 \\ \frac {1}{4} e^{2 x-2} \left (1+5 e^2\right ) & \text {True} \\ \end {array} \\ \end {array} \]
Sympy. Time used: 0.362 (sec). Leaf size: 19
from sympy import * 
x = symbols("x") 
y = Function("y") 
ode = Eq(-Piecewise((1 - x, x < 1), (0, True)) - 2*y(x) + Derivative(y(x), x),0) 
ics = {y(0): 1} 
dsolve(ode,func=y(x),ics=ics)
 
\[ y{\left (x \right )} = \begin {cases} \frac {x}{2} + \frac {5 e^{2 x}}{4} - \frac {1}{4} & \text {for}\: x < 1 \\\text {NaN} & \text {otherwise} \end {cases} \]