Exercise: second-order ODE as a system, by hand

Reduce y''−sin y=0 to a first-order system and approximate y(3) with two Euler steps and one vector RK4 step.

Reduction to a system

Consider ysiny=0y''-\sin y=0 with y(1)=2y(1)=2 and y(1)=0y'(1)=0, and approximate y(3)y(3). With the variables y1=yy_1=y, y2=yy_2=y' of the standard reduction, the system and its initial condition are:

Y=F(t,Y)=[y2siny1],Y(1)=[20]Y'=F(t,Y)=\begin{bmatrix} y_2 \\ \sin y_1 \end{bmatrix},\qquad Y(1)=\begin{bmatrix} 2 \\ 0 \end{bmatrix}

Two vector Euler steps

ExampleEuler with h=1

Apply two explicit Euler steps with h=1h=1 to the system, from Y0=[2,0]TY_0=[2,0]^T.

  1. First step: F(1,[2,0]T)=[0, sin2]T=[0, 0.9093]TF(1,[2,0]^T)=[0,\ \sin 2]^T=[0,\ 0.9093]^T.

    Y1=[20]+1[00.9093]=[20.9093]Y_1=\begin{bmatrix}2\\0\end{bmatrix}+1\cdot\begin{bmatrix}0\\0.9093\end{bmatrix}=\begin{bmatrix}2\\0.9093\end{bmatrix}
  2. Second step: F(2,[2, 0.9093]T)=[0.9093, sin2]T=[0.9093, 0.9093]TF(2,[2,\ 0.9093]^T)=[0.9093,\ \sin 2]^T=[0.9093,\ 0.9093]^T.

    Y2=[20.9093]+[0.90930.9093]=[2.90931.8186]Y_2=\begin{bmatrix}2\\0.9093\end{bmatrix}+\begin{bmatrix}0.9093\\0.9093\end{bmatrix}=\begin{bmatrix}2.9093\\1.8186\end{bmatrix}

The first component approximates the solution: y(3)2.9093y(3)\approx 2.9093.

One vector RK4 step

ExampleRK4 with h=2

Apply one RK4 step with h=2h=2 to the same system, from Y0=[2,0]TY_0=[2,0]^T at t0=1t_0=1.

  1. K1=F(1,[2, 0]T)=[0, 0.9093]TK_1=F(1,[2,\ 0]^T)=[0,\ 0.9093]^T.

  2. K2=F(2, [2,0]T+1K1)=F(2,[2, 0.9093]T)=[0.9093, 0.9093]TK_2=F\bigl(2,\ [2,0]^T+1\cdot K_1\bigr)=F(2,[2,\ 0.9093]^T)=[0.9093,\ 0.9093]^T.

  3. K3=F(2, [2,0]T+1K2)=F(2,[2.9093, 0.9093]T)=[0.9093, 0.2302]TK_3=F\bigl(2,\ [2,0]^T+1\cdot K_2\bigr)=F(2,[2.9093,\ 0.9093]^T)=[0.9093,\ 0.2302]^T, because sin2.9093=0.2302\sin 2.9093=0.2302.

  4. K4=F(3, [2,0]T+2K3)=F(3,[3.8186, 0.4604]T)=[0.4604, 0.6265]TK_4=F\bigl(3,\ [2,0]^T+2\cdot K_3\bigr)=F(3,[3.8186,\ 0.4604]^T)=[0.4604,\ -0.6265]^T.

  5. Final combination component by component:

    Y1=Y0+26(K1+2K2+2K3+K4)=[3.36590.8540]Y_1=Y_0+\frac{2}{6}\bigl(K_1+2K_2+2K_3+K_4\bigr)=\begin{bmatrix}3.3659\\0.8540\end{bmatrix}

RK4 gives y(3)3.3659y(3)\approx 3.3659 (and y(3)0.8540y'(3)\approx 0.8540). Once more the high-order method substantially corrects Euler's estimate at the same evaluation cost.