# Writing a second order ODE as a system of first order ODEs and applying one step of Euler's method

I have been struggling with this problem for awhile now and I just can't seem to get the hang of it.

The problem: Write the problem as a system of the first order and perform a step with Euler's method with step length k = 0.1.

The ODE: $$u''(t) + u^{2} = sin(t), u(0)=1, u'(0)=0$$

Here is how far I've come: My work

I don't know/understand how to perform a step with Euler's method.

Euler's Method formula: $$y_{n} = y_{n-1} + kf(t_{n-1}, y_{n-1})$$

In this case: $$y_{n} = y_{n-1} + 0.1(sin(t_{n-1}) - y_{n-1}^{2})$$

Any help would be appreciated!

You did set $$\vec y=[y_1;\,y_2]=[u;\,u']$$ and found $$\vec F(t,\vec y)=[y_2;\, \sin(t)-y_1^2]$$. Now apply the Euler formula in this setup using two-dimensional vectors as state, \vec y_{n+1}=\vec y_n+k\vec F(t_n,\vec y_n)\implies \left\{\begin{align} y_{n+1,1} &= y_{n,1}+ky_{n,2},\\ y_{n+1,2} &= y_{n,2}+k[\sin(t_n)-y_{n,1}^2]. \end{align}\right. This is how you would do it with general solver software that can compute with vector types. You would implement a function for $$\vec F$$ and the vector $$\vec y_0$$ and just let it run.
For a not so structured approach you can also call the second component $$v$$ and replace $$y_{n,1}$$ back with $$u_n$$ and $$y_{n,2}$$ with $$v_n=u_n'$$, so that \begin{align} u_{n+1}&=u_n+kv_n,\\ v_{n+1}&=v_n+ka_n=v_n+k[\sin(t_n)-u_n^2]. \end{align}
• @Lutz_Lehmann This is what I do not know how to do. I am also unfamiliar with the notation $y_{n,1}$, $y_{n,2}$, could you explain what that means? The introduction to linear algebra by my professor has been very brief and not well done. Jan 6 '20 at 14:53
• Then perhaps call the second component $v$ and replace $y_{n,1}$ back with $u_n$ and $y_{n,2}$ with $v_n=u_n'$. You just can not cross-mix the update equations, a system is different from a scalar first-order equation. Jan 6 '20 at 15:13