Consider a slightly different version of the square wave.
\begin{equation*}
f(t) = \left\{ \begin{matrix} 1 \amp t \in [2n, 2n+1) \\ -1
\amp t \in [2n+1, 2n+2) \end{matrix} \right.
\end{equation*}
Using initial conditions \(y(0) = y^\prime(0)= 0\) I solve the equation \(y^{\prime \prime} + y = f(t)\text{.}\)
\begin{align*}
(s^2+1)Y \amp = \frac{1}{1-e^{-2s}} \int_0^2 e^{-st} f(t)
dt\\
\amp = \frac{1}{1-e^{-2s}} \left[ \int_0^1 e^{-st} dt -
\int_1^2 e^{-st} dt \right]\\
\amp = \frac{1}{1-e^{-2s}} \left[ \left.
\frac{e^{-st}}{-s} \right|_0^1 + \left. \frac{e^{-st}}{s}
\right|_1^2 \right]\\
(s^2 + 1) Y \amp = \frac{1}{1-e^{2s}} \left[ \frac{-e^{-s}}{s} +
\frac{1}{s} + \frac{e^{-2s}}{s} - \frac{e^{-s}}{s}
\right]
\end{align*}
After solving the integral and simplifying the result, I get an algebraic equation in \(Y\text{.}\) I solve for \(Y\text{.}\) Then I use partial fractions to split up the rational function and geometric series to expand the term with an exponential decay in the denominator.
\begin{align*}
Y \amp = \frac{1-2s^{-s} + e^{-2s}}{s(s^2+1)}
\frac{1}{1-e^{-2s}}\\
\amp = \frac{1}{s(s^2+1)} (1-2e^{-s} + e^{-2s}) ( 1 -
e^{-2s} + e^{-4s} - e^{-6s} + e^{-8s} - \ldots )\\
\amp = \left( \frac{-s}{s^2+1} + \frac{1}{s} \right) (1 -
2e^{-s} + 2e^{-3s} - 2e^{-5s} + 2e^{-7s} - \ldots )
\end{align*}
Then I apply the inverse transform and simplify it into a single sum.
\begin{align*}
y \amp = 1 - \cos t - 2u_1(t) (1-\cos(t-1)) + 2u_3(t)
(1-\cos(t-3))\\
\amp - 2u_5 (t) (1-\cos(t-5)) + 2 u_7(t) (1 -
\cos (t-7) ) - \ldots\\
\amp = 1 - \cos t + 2\sum_{k=0}^\infty (-1)^{k+1} u_{2k+1}
(t) (1 - \cos(t-(2k+1)))
\end{align*}
As with the previous square wave solution in Example 5.7.4, this solution involves an infinite series of shifts, each one slightly further along. Unusual periodic functions almost always lead to an infinite series of shifts.