# Solving an ODE with a piecewise function

How can I solve $$y'' + y = \begin{cases} \sin(t) & 0 \leq t < \pi \\ \cos(t) & \pi \leq t < \infty \end{cases}$$

using Laplace transforms? I also have the initial conditions $$y(0) = 1$$ and $$y'(0) = 0$$.

I'm familiar with doing Laplace transforms when the functions on the RHS are much simpler; however, I'm sort of confused about how to handle the piecewise function.

I tried doing the integral definition of Laplace transform, but it got really messy, so I think there is a better way to do it. The book I'm using had some examples which cleverly used the heaviside function, but I'm not sure about how I would go about doing that since we are dealing with trignometric functions here.

I would really appreciate any help.

• Solve over $[0,\pi]$. Obtain $y (\pi)$ and use it as the initial condition for $t \geq \pi$. – Rodrigo de Azevedo Mar 26 at 5:39

## 1 Answer

The method involving the Heaviside function doesn't really depend on the form of the piecewise function. The examples from your text should work the same with trig functions, if you can follow them.

The RHS function can be rewritten as

\begin{align} f(t) &= \sin(t)\cdot\big[u(t)-u(t-\pi)\big] + \cos(t)\cdot u(t-\pi) \\ &= \sin(t)\cdot u(t) + \big[-\sin(t) + \cos(t)\big]\cdot u(t-\pi) \\ &= \sin(t)\cdot u(t) + \big[-\sin\big((t-\pi)+\pi\big) + \cos\big((t-\pi)+\pi\big)\big]\cdot u(t-\pi) \\ &= \sin(t)\cdot u(t) + \big[\sin(t-\pi) - \cos(t-\pi)\big]\cdot u(t-\pi) \\ \end{align}

where $$u(t)$$ denotes the Heaviside step function. Using the shift theorem we obtain the Laplace transform

$$F(s) = \frac{1}{s^2+1} + e^{-\pi s}\left[\frac{1}{s^2+1} - \frac{s}{s^2+1}\right]$$