76.15.35 problem 37

Internal problem ID [17605]
Book : Differential equations. An introduction to modern methods and applications. James Brannan, William E. Boyce. Third edition. Wiley 2015
Section : Chapter 4. Second order linear equations. Section 4.5 (Nonhomogeneous Equations, Method of Undetermined Coefficients). Problems at page 260
Problem number : 37
Date solved : Monday, March 31, 2025 at 04:22:15 PM
CAS classification : [[_2nd_order, _linear, _nonhomogeneous]]

\begin{align*} y^{\prime \prime }+y&=\left \{\begin {array}{cc} t & 0\le t \le \pi \\ \pi \,{\mathrm e}^{\pi -t} & \pi <t \end {array}\right . \end{align*}

With initial conditions

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

Maple. Time used: 0.246 (sec). Leaf size: 41
ode:=diff(diff(y(t),t),t)+y(t) = piecewise(0 <= t and t <= Pi,t,Pi < t,Pi*exp(-t+Pi)); 
ic:=y(0) = 0, D(y)(0) = 1; 
dsolve([ode,ic],y(t), singsol=all);
 
\[ y = \left \{\begin {array}{cc} \sin \left (t \right ) & t <0 \\ t & t <\pi \\ -\frac {\sin \left (t \right ) \pi }{2}-\frac {\cos \left (t \right ) \pi }{2}+\frac {\pi \,{\mathrm e}^{\pi -t}}{2}-\sin \left (t \right ) & \pi \le t \end {array}\right . \]
Mathematica. Time used: 0.096 (sec). Leaf size: 47
ode=D[y[t],{t,2}]+y[t]==Piecewise[{  {t,0<=t<=Pi}, {Pi*Exp[Pi-t],t>Pi} }]; 
ic={y[0]==0,Derivative[1][y][0] == 1}; 
DSolve[{ode,ic},y[t],t,IncludeSingularSolutions->True]
 
\[ y(t)\to \begin {array}{cc} \{ & \begin {array}{cc} \sin (t) & t\leq 0 \\ t & 0<t\leq \pi \\ \frac {1}{2} \left (-\pi \cos (t)-(2+\pi ) \sin (t)+e^{\pi -t} \pi \right ) & \text {True} \\ \end {array} \\ \end {array} \]
Sympy. Time used: 0.486 (sec). Leaf size: 24
from sympy import * 
t = symbols("t") 
y = Function("y") 
ode = Eq(-Piecewise((2, (t >= 0) & (t <= pi)), (pi*exp(pi - t), t > pi)) + y(t) + Derivative(y(t), (t, 2)),0) 
ics = {} 
dsolve(ode,func=y(t),ics=ics)
 
\[ y{\left (t \right )} = C_{1} \sin {\left (t \right )} + C_{2} \cos {\left (t \right )} + \begin {cases} 2 & \text {for}\: t \geq 0 \wedge t \leq \pi \\\frac {\pi e^{\pi - t}}{2} & \text {for}\: t > \pi \\\text {NaN} & \text {otherwise} \end {cases} \]