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?
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
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
Define a function that takes
x(array) and returnsdx(array) withdx[1] = x[2]anddx[2] = - g * sin(x[1]) / l. This way is simpler to evaluate the system, and your code is easier to debugHere's a solution using $h = 0.01$ in python, just for reference