B Euler's method for second order DE

1. Oct 4, 2016

Karol

Can the Euler approximation method be used to solve higher order DE?
I have $\ddot x=\omega^2 x$ which i rewrite as $y''=\omega^2y$. initial conditions y(0)=0, y'(0)=1.
The Euler method: $y_{n+1}=y_n+h\cdot y'_n$. i use this to make:
$$y''_{n+1}=y'_n+h\cdot y''_n~~\rightarrow~~\omega^2y_{n+1}=y'_n+h\omega^2 y_n$$
$$\omega^2(y_n+hy'_n)=y'_n+h\omega^2 y_n$$
$$\rightarrow~y'_n=\left[ \frac{\omega^2(1-h)}{1-\omega^2h} \right]y_n$$
But this contradicts the initial condition y'(0)=1, after i substitute y(0)=0 in the formula i found.

2. Oct 4, 2016

BvU

Wouldn't the Euler method dictate $$y'_{n+1} = y'_n + h\omega^2y_n$$ ?

3. Oct 6, 2016

Krylov

Yes, every explicit first order method can be used to solve higher-order DE by writing the DE in vector form as a system of first-order DE, also see below.
I do not quite understand the purpose of introducing $y$, but it does no harm. Also, this equation looks like a free harmonic oscillator. Are you sure there should not be a minus in front of $\omega^2$?
I think that the OP and @BvU both have one half of the method for this problem .

As I alluded to at the start, you can solve higher order DE by converting them into a system of first order DE. Although not strictly necessary, this works best by introducing new symbols for the derivatives. For this example, set $v := y'$, then the DE $y''(t) = \omega^2y(t)$ is equivalent to
\left\{ \begin{align*} y'(t) &= v(t)\\ v'(t) &= \omega^2y(t) \end{align*} \right.
with the initial conditions $y(0) = 0$, $v(0) = 1$. Then Euler forward with stepsize $h > 0$ just reads
\begin{align*} \begin{bmatrix} y_{n+1}\\ v_{n+1} \end{bmatrix} &\approx \begin{bmatrix} y_n\\ v_n \end{bmatrix} + h \begin{bmatrix} y'(nh)\\ v'(nh) \end{bmatrix}\\ &= \begin{bmatrix} y_n\\ v_n \end{bmatrix} + h \begin{bmatrix} v_n\\ \omega^2y_n \end{bmatrix} \end{align*}
where $y_n := y(nh)$ and $v_n := v(nh)$ for $n = 0, 1,\ldots$. The first component is what the OP called the Euler method, while the second component appears in post #2.

4. Oct 7, 2016

Karol

It is taken from a mathematics book, teaching DE, not a physics book.
I thank you very much BvU and Krylov.
How do you quote exactly also the equations in the posts, since when i use the "+Quote" function that is given in this site, or i mark a part of a post and select "+Quote" from the context menu that appears, and then insert these quotes in the reply box the equations come out messed, while the text is good. i manually fix these equations, almost completely write them anew.
And also, how can you copy a poster's name, like Krylov did in the last post:

5. Oct 7, 2016

Krylov

Ok. Whenever I see an $\omega^2$ somewhere, I start to think of $\tfrac{k}{m}$.
You are welcome!
I recognize this and it is a bit uncomfortable. Probably there are better ways, but what usually do, is put the cursor where I want the quote (with formulas) to appear and then press "reply". This quotes the entire message with formulas correctly. Then I remove the excess text that I do not want quoted.

You can also right-click on an equation, then "Show Math As", then "TeX Commands". This opens a pop-up containing the $\LaTeX$ source. That context menu has some other options, too, it appears.
You write the member name with an "@" in front, like @Karol. When the member has enabled this, it will show him a message that he has been "mentioned" in a certain thread.

6. Oct 7, 2016

Karol

Thank you very much BvU and Krylov