71.15.2 problem 4 (b)

Internal problem ID [14473]
Book : Ordinary Differential Equations by Charles E. Roberts, Jr. CRC Press. 2010
Section : Chapter 5. The Laplace Transform Method. Exercises 5.4, page 265
Problem number : 4 (b)
Date solved : Monday, March 31, 2025 at 12:27:58 PM
CAS classification : [[_2nd_order, _linear, _nonhomogeneous]]

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

Using Laplace method With initial conditions

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

Maple. Time used: 0.185 (sec). Leaf size: 126
ode:=diff(diff(y(x),x),x)-diff(y(x),x)-2*y(x) = piecewise(2 <= x and x < 4,1,0); 
ic:=y(0) = 0, D(y)(0) = 1; 
dsolve([ode,ic],y(x),method='laplace');
 
\[ y = -\frac {\left (\left \{\begin {array}{cc} {\mathrm e}^{-x}-{\mathrm e}^{2 x} & x <2 \\ \frac {1}{2}+{\mathrm e}^{-2}-{\mathrm e}^{4} & x =2 \\ {\mathrm e}^{-x}-{\mathrm e}^{2 x}+\frac {3}{2}-{\mathrm e}^{2-x}-\frac {{\mathrm e}^{-4+2 x}}{2} & x <4 \\ 1+{\mathrm e}^{-4}-{\mathrm e}^{8}-\frac {{\mathrm e}^{4}}{2}-{\mathrm e}^{-2} & x =4 \\ -{\mathrm e}^{2 x}+\frac {{\mathrm e}^{-8+2 x}}{2}+{\mathrm e}^{4-x}+{\mathrm e}^{-x}-{\mathrm e}^{2-x}-\frac {{\mathrm e}^{-4+2 x}}{2} & 4<x \end {array}\right .\right )}{3} \]
Mathematica. Time used: 0.041 (sec). Leaf size: 127
ode=D[y[x],{x,2}]-D[y[x],x]-2*y[x]==Piecewise[{ {1,2<=x<4},{0,True}}]; 
ic={y[0]==0,Derivative[1][y][0] ==1}; 
DSolve[{ode,ic},y[x],x,IncludeSingularSolutions->True]
 
\[ y(x)\to \begin {array}{cc} \{ & \begin {array}{cc} \frac {1}{3} e^{-x} \left (-1+e^{3 x}\right ) & x\leq 2 \\ \frac {1}{6} e^{-x-4} \left (-2 e^4+2 e^6+e^{3 x}-3 e^{x+4}+2 e^{3 x+4}\right ) & 2<x\leq 4 \\ \frac {1}{6} e^{-x-8} \left (-2 e^8+2 e^{10}-2 e^{12}-e^{3 x}+e^{3 x+4}+2 e^{3 x+8}\right ) & \text {True} \\ \end {array} \\ \end {array} \]
Sympy
from sympy import * 
x = symbols("x") 
y = Function("y") 
ode = Eq(-Piecewise((1, (x >= 2) & (x < 4)), (0, True)) - 2*y(x) - Derivative(y(x), x) + Derivative(y(x), (x, 2)),0) 
ics = {y(0): 0, Subs(Derivative(y(x), x), x, 0): 1} 
dsolve(ode,func=y(x),ics=ics)