Equations of motion are determined in MatLab based on Lagrangian formula which summarizes dynamics of the entire system. Acceleration of each link is computed by solving system of equations obtained from partial differential Lagrange's equations. Simple integration results in trajectory. With little changes any multiple pendulum can be solved.
Watch video on youtube: https://www.youtube.com/watch?v=cp731cKgoHw