68.21.3 problem 17

Internal problem ID [17928]
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 : 17
Date solved : Thursday, October 02, 2025 at 02:29:57 PM
CAS classification : [[_2nd_order, _linear, _nonhomogeneous]]

\begin{align*} x^{\prime \prime }+x&=\left \{\begin {array}{cc} t & 0\le t <1 \\ 2-t & 1\le t <2 \\ 0 & 2\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.199 (sec). Leaf size: 56
ode:=diff(diff(x(t),t),t)+x(t) = piecewise(0 <= t and t < 1,t,1 <= t and t < 2,2-t,2 <= 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 \\ t -\sin \left (t \right ) & t <1 \\ 2 \sin \left (t -1\right )-\sin \left (t \right )-t +2 & t <2 \\ -\sin \left (t -2\right )+2 \sin \left (t -1\right )-\sin \left (t \right ) & 2\le t \end {array}\right . \]
Mathematica. Time used: 0.035 (sec). Leaf size: 63
ode=D[x[t],{t,2}]+x[t]==Piecewise[{{t,0<=t<1},{2-t,1<=t<2},{0,t>=2}}]; 
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 \\ t-\sin (t) & 0<t\leq 1 \\ -t-2 \sin (1-t)-\sin (t)+2 & 1<t\leq 2 \\ -4 \sin ^2\left (\frac {1}{2}\right ) \sin (1-t) & \text {True} \\ \end {array} \\ \end {array} \end{align*}
Sympy. Time used: 0.348 (sec). Leaf size: 14
from sympy import * 
t = symbols("t") 
x = Function("x") 
ode = Eq(-Piecewise((t, (t >= 0) & (t < 1)), (2 - t, (t >= 1) & (t < 2)), (0, t >= 2)) + 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} t & \text {for}\: t \geq 0 \wedge t < 1 \\2 - t & \text {for}\: t \geq 1 \wedge t < 2 \\0 & \text {for}\: t \geq 2 \\\text {NaN} & \text {otherwise} \end {cases} - \sin {\left (t \right )} \]