68.21.1 problem 15

Internal problem ID [17926]
Book : INTRODUCTORY DIFFERENTIAL EQUATIONS. Martha L. Abell, James P. Braselton. Fourth edition 2014. ElScAe. 2014
Section : Chapter 5. Applications of Higher Order Equations. Exercises 5.3, page 249
Problem number : 15
Date solved : Thursday, October 02, 2025 at 02:29:52 PM
CAS classification : [[_2nd_order, _linear, _nonhomogeneous]]

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

With initial conditions

\begin{align*} x \left (0\right )&=0 \\ x^{\prime }\left (0\right )&=0 \\ \end{align*}
Maple. Time used: 0.088 (sec). Leaf size: 25
ode:=diff(diff(x(t),t),t)+x(t) = piecewise(0 <= t and t < Pi,1,Pi <= t,0); 
ic:=[x(0) = 0, D(x)(0) = 0]; 
dsolve([ode,op(ic)],x(t), singsol=all);
 
\[ x = \left \{\begin {array}{cc} 0 & t <0 \\ -\cos \left (t \right )+1 & t <\pi \\ -2 \cos \left (t \right ) & \pi \le t \end {array}\right . \]
Mathematica. Time used: 0.022 (sec). Leaf size: 29
ode=D[x[t],{t,2}]+x[t]==Piecewise[{{1,0<=t<Pi},{0,t>=Pi}}]; 
ic={x[0]==0,Derivative[1][x][0 ]==0}; 
DSolve[{ode,ic},x[t],t,IncludeSingularSolutions->True]
 
\begin{align*} x(t)&\to \begin {array}{cc} \{ & \begin {array}{cc} 0 & t\leq 0 \\ 1-\cos (t) & 0<t\leq \pi \\ -2 \cos (t) & \text {True} \\ \end {array} \\ \end {array} \end{align*}
Sympy. Time used: 0.165 (sec). Leaf size: 10
from sympy import * 
t = symbols("t") 
x = Function("x") 
ode = Eq(-Piecewise((1, (t >= 0) & (t < pi)), (0, t >= pi)) + x(t) + Derivative(x(t), (t, 2)),0) 
ics = {x(0): 0, Subs(Derivative(x(t), t), t, 0): 0} 
dsolve(ode,func=x(t),ics=ics)
 
\[ x{\left (t \right )} = \begin {cases} 1 & \text {for}\: t \geq 0 \wedge t < \pi \\0 & \text {for}\: t \geq \pi \\\text {NaN} & \text {otherwise} \end {cases} - \cos {\left (t \right )} \]