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

291 Views Asked by At

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!

1

There are 1 best solutions below

2
On BEST ANSWER

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}

You just can't cross-mix the update equations, a system is different from a scalar first-order equation.