How to apply improved Euler method to a systems of differential equation?

1.3k Views Asked by At

I have the following problem (linearized pendulum problem):

$x_1'=x_2$

$x_2'=-\frac{g}{L}*sin(x_1)$

with the following initial condition:

$x_1(t_0)=0$

$x_2(t_0)=0$

Improved Euler Method says that:

$Y_{k+1}=Y_k+\frac{h}{2}*[f(t_k, Y_k)+f(t_{k+1}, Y_k+h*f(t_k, Y_k))]$

In this case I have done the following:

$x_{1, k+1}=x_{1, k}+\frac{h}{2}*[x_{1, k}+(x_{1, k}+h*x_{1, k})]$

$x_{2, k+1}=x_{2, k}+\frac{h}{2}*[-\frac{g}{L}*sin(x_{1, k})+-\frac{g}{L}*sin(x_{1, k}+h*(-\frac{g}{L}*sin(x_{1, k}))))]$

Where is my mistake?

2

There are 2 best solutions below

0
On

One of the most common problems in numerical integration is the time step. Make sure it is small enough so the system does not explode. Beyond that here are a couple of tips

  1. The system has a fixed point at $(x_1, x_2) = 0$. That means that if your initial condition starts there, the system will not move

  2. Define a function that takes x (array) and returns dx (array) with dx[1] = x[2] and dx[2] = - g * sin(x[1]) / l. This way is simpler to evaluate the system, and your code is easier to debug

  3. Here's a solution using $h = 0.01$ in python, just for reference

enter image description here

0
On

You have to use the correct right side for the increments of the variables. If $$ x_1'=f(x_2)\\ x_2'=g(x_1) $$ then the method step reads $$ x_{1,k+1}=x_{1,k}+\frac h2[f(x_{2,k})+f(x_{2,k}+hg(x_{1,k}))]\\ x_{2,k+1}=x_{2,k}+\frac h2[g(x_{1,k})+g(x_{1,k}+hf(x_{1,k}))]\\ $$ To keep track of these mixings you can either use a vector-based code or compute the steps like in the standard formulation of Runge-Kutta methods, \begin{align} Δ_1x_1 &= f(x_{2,k})Δt,& Δ_1x_2 &= g(x_{1,k})Δt,\\ Δ_2x_1 &= f(x_{2,k}+Δ_1x_2)Δt,& Δ_2x_2 &= g(x_{1,k}+Δ_1x_1)Δt,\\[2em]\hline x_{1,k+1}&=x_{1,k}+\frac{Δ_1x_1+Δ_2x_1}2,&x_{2,k+1}&=x_{2,k}+\frac{Δ_1x_2+Δ_2x_2}2. \end{align}