I have set up a spreadsheet in Excel to solve the double pendulum problem using RK4 on the four first order DEs. However it isn't working, as the energy in the system is increasing drastically, instead of staying constant. I have spent days (literally) checking the Lagrangian and the spreadsheet entries, and I can't find any faults. I wonder if I am mis-applying the RK4 procedure. I can't find any examples of this in Excel - only Matlab, which is quite different, and I don't have it! I'm desperate and so thought I would post here.
I have four first order DEs. The first two are simple W'=Y, X'=Z. Y' & Z' are both very long with terms in W, X, Y & Z. So, I have
W'=f(t,Y)
X'=f(t,Z)
Y'=f(t,X,Y,Z)
Z'=f(t,X,Y,Z)
I calculate
Wn+1 = Wn + h/6*(J1 + 2*J2 + 2*J3 + J4)
Xn+1 = Xn + h/6*(K1 + 2*K2 + 2*K3 + K4)
Yn+1 = Yn + h/6*(L1 + 2*L2 + 2*L3 + L4)
Zn+1 = Zn + h/6*(M1 + 2*M2 + 2*M3 + M4)
The values of these constants are worked out as follows: (Is this where I'm going wrong?)
J1 = f(tn, Yn)
J2 = f(tn + h/2, Yn + h/2*L1)
J3 = f(tn + h/2, Yn + h/2*L2)
J4 = f(tn + h, Yn + h*L3)
The values for K1, K2, K3 & K4 are calculated in the same way using Zn & M1, M2 M3 & M4.
As Y is a function f(t, W, X, Y, Z), I calculate as follows:
L1 = f(tn, Wn, Xn, Yn, Zn)
L2 = f(tn + h/2, Wn + h/2*J1, Xn + h/2*K1, Yn + h/2*L1, Zn + h/2*M1)
L3 = f(tn + h/2, Wn + h/2*J2, Xn + h/2*K2, Yn + h/2*L2, Zn + h/2*M2)
L4 = f(tn + h, Wn + h*J3, Xn + h*K3, Yn + h*L3, Zn + h*M3).
The values for M1, M2, M3 & M4 used to calculate Z were computed in the exact same manner as for L1 etc. above.
If anyone can identify a flaw in my methodology and let me know I would be very grateful.
The goal is to use a fourth order Runge-Kutta Method to solve two converted $2nd$ order differential equations into four $1st$ order differential equations given by the double pendulum.
Depending on initial conditions, this system can show chaotic behavior, so play around with initial conditions (or seek them out on the web).
The system is given by:
$$ \left\{ \begin{array}{c} \theta_1' = \omega_1 \\ \theta_2' = \omega_2 \\ \omega_1' = \dfrac{-g(2 m_1 + m_2) \sin \theta_1 - m_2 g \sin(\theta_1 - 2 \theta_2) - 2 \sin(\theta_1 - \theta_2)m_2(\omega_2^2 L_2 + \omega_1^2 L_1 \cos(\theta_1 - \theta_2))}{L_1(2 m_1 + m_2 - m_2 \cos(2 \theta_1 - 2 \theta_2))} \\ \omega_2' = \dfrac{2 \sin(\theta_1 -\theta_2)(\omega_1^2 L_1(m_1 + m_2) + g(m_1 + m_2) \cos(\theta_1) + \omega_2^2 L_2 m_2 \cos(\theta_1 - \theta_2))}{L_2(2 m_1 + m_2 - m_2 \cos(2 \theta_1 - 2 \theta_2))} \end{array} \right. $$
Here is an implementation and it must be done in the order shown because of the dependencies. I changed some of the variable names, so you will have to adapt it, but it is exactly your problem. I used the equations from the web site you linked.
Of course, there are much cleaner approaches in code, but since you are using a spreadsheet, this gives everything in a form like you posted. Here are various plots for each of the parameters with each other for the initial conditions (recall that this system can exhibit chaotic behavior based on the initial conditions).