# Solving ODE with Laplace transform

1. Oct 16, 2015

### Incand

1. The problem statement, all variables and given/known data
Let
$f(t)= \begin{cases} \sin t , \; \; 0 \le t < \pi \\ 0 , \; \; \; \; \; \text{else.} \end{cases}$
Use Laplace transform to solve the initial value problem
$x'(t)+x(t)=f(t), \; \; \; x(0)=0.$

2. Relevant equations
Some useful Laplace transforms:
$\mathscr{L}\left(f'(t)\right) = z\mathscr{L}\left(f(z)\right)-f(0)$
$\mathscr{L}\left(H(t-a)f(t-a)\right) = e^{-az}\mathscr{L}\left(f(z) \right)$
for $a >0$ and $H(t)$ is the Heaviside function. (i.e. we shift the function)
$\mathscr{L}\left( \sin ct\right) = \frac{c}{z^2+c^2}$
$\mathscr{L}\left(t^ve^{ct}\right) = \frac{\Gamma (v+1)}{(z-c)^{v+1}}$
for $v > -1$ and $\Gamma$ is the gamma function.

3. The attempt at a solution
We write $f(t) = (H(t)-H(t-\pi))\sin t$. Transforming the ODE we get
$z\mathscr{L}\left(x(t)\right)-x(0)+\mathscr{L}\left(x(t)\right)=\mathscr{L}\left(f(t)\right)$
Rearranging (We don't actually need compute the Laplace transform here I think as long as we're convinced it does exist.)
$\mathscr{L}\left( x(t) \right) = \frac{1}{z+1}\mathscr{L}\left(f(t)\right)$
Taking the inverse Laplace transform we have
$x(t) = (e^{-t})*((H(t)-H(t-\pi)\sin t)$
Computing the convolution we have
$x(t) = \int_{-\infty}^\infty \left(e^{y-t}(H(-y)-H(-y+\pi)\sin -y \right)dy = \int_{-\infty}^0 -e^{y-t}\sin y dy + \int_{-\infty}^\pi e^{y-t}\sin y dy = \frac{e^{-t}}{2} + \frac{e^{-t}+\pi}{2} = \frac{e^{-t}}{2}(1+e^{\pi})$

Not entirely sure what I'm doing wrong here. The solution should be
$x(t) = \begin{cases} \frac{e^{-t}-\cos t + \sin t}{2} \; \; t < 0 < \pi\\ \frac{e^{-t}}{2}(1+e^{\pi}) \; \; t > \pi \end{cases}$
The solution for $t > \pi$ looks suspiciously alike to my solution.

On the other hand if we calculate the Laplace transform earlier we have
$\mathscr{L}\left( H(t-\pi)\sin(t) \right) = \mathscr{L}\left( -H(t-\pi)\sin(t-\pi) \right) = \frac{-e^{\pi z}}{z^2+1}$ so we have
$\mathscr{L}\left( f(t) \right) = \frac{1-e^{\pi z}}{(z^2+1)(z+1)}$
Interesting enough the first part $\frac{1}{(z^2+1)(z+1)}$ has the Inverse Laplace transform
$\frac{e^{-t}-\cos t + \sin t}{2}$ which also looks similar.

I kept out most of the integral calculations to make the post a bit shorter, they're all pretty much integration by parts twice. I also checked them with wolfram alpha to make sure they're correct.

Last edited: Oct 16, 2015
2. Oct 16, 2015

### Zondrina

I see something wrong in the second step.

You want to solve:

$$x' + x = [u(t) - u(t - \pi)] sin(t), \quad x(0) = 0$$

When you take the Laplace transform of both sides you should get:

$$sX(s) - x(0) + X(s) = \mathscr{L} \{ u(t) sin(t) \} - \mathscr{L} \{ u(t - \pi) sin(t) \}$$

Cleaning things up a bit:

$$X(s) [s + 1] = \frac{1}{s^2 + 1} - \mathscr{L} \{ u(t - \pi) sin([t - \pi] + \pi) \}$$

Now use the identity $\sin(A + B) = \sin(A) \cos(B) + \sin(B) + \cos(A)$ to find the remaining Laplace transform. You will also have to make use of the fact $\sin(A - B) = \sin(A) \cos(B) - \sin(B) + \cos(A)$ along the way.

3. Oct 16, 2015

### Incand

Sorry I interchanged $f$ and $x$ in some places, also I made a sign error. Was there a larger error? When you say second step is that second line or the equation below that?

I guess you misstyped in an extra plus-sign in the identities here. As far as I can tell using those identities they only tell me that $\sin (x\pm \pi ) = -\sin (x\pm \pi)$ if I'm supposed to use them right away. I still end up with the same Laplace transform
$(s+1)X(s) = \frac{1}{s^2+1}+\mathscr{L}[u(t-\pi)\sin (t-\pi) = \frac{1}{s^2+1}+\frac{e^{-\pi s}}{s^2+1}$
which give us
$X(s) = \frac{1+e^{-\pi s}}{(z^2+1)(z+1)}$.
Is it correct this far or this wasn't what you meant? I had a sign error here earlier.

4. Oct 16, 2015

### Ray Vickson

You should have
$$\mathscr{L}\left( f(t) \right) = \frac{1\; {\large \bf +} \; e^{\pi z}}{(z^2+1)(z+1)}$$

5. Oct 16, 2015

### Incand

Love the large plus sign! I think this was what zondrina pointed out earlier as well and I fixed in the next post. I however believe it should be $e^{\Huge{-}\pi z}$.
I got it now. Here's the rest of the solution:
$\mathscr{L}\frac{1+e^{-\pi t}}{(z+1)(z^2+1)} = \frac{e^{-t}-\cos t+\sin t}{2}+ H(t-\pi )\frac{e^{-t+\pi}+\cos x - \sin x}{2}$
which is equal too the answer for the intervals! Thanks both of you!

6. Oct 17, 2015

### Zondrina

Just a small error I see in the solution. You should have:

$$X(s) = \frac{1 + e^{- \pi s}}{(s+1) (s^2 + 1)}$$

From here a partial fraction expansion will yield $x(t)$.

7. Oct 17, 2015

### Incand

Yea I typed the wrong variable (again). Partial fractions is a really cool way of doing it. I didn't think of that. It however seems like quite a lot of work. I tried it now but after juggling 9 different variables in my ansatz for 15 min I just decided to be happy with the solution I already did.
How I did it was using that the Laplace transform of the convolution of two functions is the product of two functions. You end up with a really simple integral that way since the heaviside functions actually make it easier. In the end all you have to compute is $e^{-t}\int_0^t e^y\sin y dy$ which can be done with integration by parts twice. The integrating limits follow directly from the heaviside functions.

Last edited: Oct 17, 2015
8. Oct 17, 2015

### Zondrina

The partial fraction method is arguably one of the fastest. You should try it for some simple cases just to get used to setting up the equations.

The convolution theorem can be useful, but it is also time consuming. Two integration by parts probably take longer on average than solving a few linear equations, but choose whichever method you prefer.