# Solving two coupled non-linear second order differential equations numerically

I have encountered the following system of differential equations in lagrangian mechanics. Can you suggest a numerical method, with relevant links and references on how can I solve it, and the implementation in C (if possible) Also, is there a shorter implementation on Matlab or Mathematica?

\begin{align*} mx \dot y^2 + mg\cos(y) - Mg - (m+M)\,\ddot x &= 0 \\ g\sin(y) + 2\dot x\dot y + x \,\ddot y &= 0 \end{align*}

where $\dot x$ or $\dot y$ are time derivatives, and the double dots indicate a 2nd derivative wrt time.

• @ramanujan_dirac: Check my edit. Is this the set of equations you meant to type? – Paul Sep 6 '12 at 18:10
• @Paul: Sorry, it was actually M + m, where m, M are distinct constants in general. I have edited to reflect the same. – user1717 Sep 6 '12 at 18:35

\left\{ \begin{aligned} x_1' &= x_2 \\ y_1' & = y_2 \\ x_2' &= x_1 y_2 + g \cos y_1 -(M+m)g/m \\ y_2' &= -g(\sin y_1) /x_1 - 2x_2 y_2/x_1 \end{aligned} \right.
Now you could use MATLAB's ode45 or ode23 to solve it, if you wanna implement the method on C, I believe there are many pkgs available there on the internet, like this.