Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

10.11 ODE with periodic solution

Consider the ODE system

x′=−y,y′=xx(0)=1,y(0)=0\begin{gather} x' = -y, \qquad y' = x \\ x(0) = 1, \qquad y(0) = 0 \end{gather}

The exact solution is

x(t)=cos⁡(t),y(t)=sin⁡(t)x(t) = \cos(t), \qquad y(t) = \sin(t)

This solution is periodic. It also has a quadratic invariant

x2(t)+y2(t)=1,∀tx^2(t) + y^2(t) = 1, \qquad \forall t

10.11.1Forward Euler scheme

<Figure size 640x480 with 1 Axes>

The phase space trajectory is spiralling outward.

10.11.2Backward Euler scheme

xn=xn−1−hyn,yn=yn−1+hxnx_n = x_{n-1} - h y_n, \qquad y_n = y_{n-1} + h x_n

Eliminate yny_n from first equation and solve for xnx_n to get

xn=xn−1−hyn−11+h2x_n = \frac{x_{n-1} - h y_{n-1}}{1 + h^2}

and now yny_n can also be computed.

<Figure size 640x480 with 1 Axes>

The phase space trajectory is spiralling inward.

10.11.3Trapezoidal scheme

xn=xn−1−h2(yn−1+yn),yn=yn−1+h2(xn−1+xn)x_n = x_{n-1} - \frac{h}{2}(y_{n-1} + y_n), \qquad y_n = y_{n-1} + \frac{h}{2}(x_{n-1} + x_n)

Eliminate yny_n from first equation

xn=(1−14h2)xn−1−hyn−11+14h2x_n = \frac{ (1-\frac{1}{4}h^2) x_{n-1} - h y_{n-1} }{1 + \frac{1}{4}h^2}

and now yny_n can also be computed.

<Figure size 640x480 with 1 Axes>

The phase space trajectory is exactly the unit circle.

Multiply first equation by xn+xn−1x_n + x_{n-1} and second equation by yn+yn−1y_n + y_{n-1}

(xn+xn−1)(xn−xn−1)=−h2(xn+xn−1)(yn+yn−1)(x_n + x_{n-1})(x_n - x_{n-1}) = - \frac{h}{2}(x_n + x_{n-1})(y_n + y_{n-1})
(yn+yn−1)(yn−yn−1)=+h2(xn+xn−1)(yn+yn−1)(y_n + y_{n-1})(y_n - y_{n-1}) = + \frac{h}{2}(x_n + x_{n-1})(y_n + y_{n-1})

Adding the two equations we get

xn2+yn2=xn−12+yn−12x_n^2 + y_n^2 = x_{n-1}^2 + y_{n-1}^2

Thus the Trapezoidal method is able to preserve the invariant.

10.11.4Partitioned Euler

This is a symplectic Runge-Kutta method. xx is updated explicitly and yy is updated implicitly.

xn=xn−1−hyn−1,yn=yn−1+hxnx_n = x_{n-1} - h y_{n-1}, \qquad y_n = y_{n-1} + h x_{n}

The update of yy uses the latest updated value of xx.

<Figure size 640x480 with 1 Axes>

We get very good results, even though the method is only first order. We can also switch the implicit/explicit parts

yn=yn−1+hxn−1,xn=xn−1−hyny_n = y_{n-1} + h x_{n-1}, \qquad x_n = x_{n-1} - h y_n

10.11.5Classical RK4 scheme

We test this method for a longer time.

<Figure size 640x480 with 1 Axes>

RK4 is a more accurate method compared to forward/backward Euler schemes, but it still loses total energy. The trajectory spirals inwards towards the origin.