5
$\begingroup$

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.

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

3 Answers 3

5
$\begingroup$

Why implement it by hand? Matlab, Maple and Mathematica all have tools builtin to solve differential equations numerically, and they use far better methods than you could implement yourself in finite time. In Matlab, you want to look at ode45. In Maple it's called dsolve (with the 'numeric' option set), in Mathematica it is NDSolve.

$\endgroup$
5
$\begingroup$

You could use Runge-Kutta method to solve this system numerically, first rewrite your second order equation as a first order system by doing following substitution trick:

$$ \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.

$\endgroup$
1
$\begingroup$

Runge-Kutta methods such as (4,5) are also available in the GNU Scientific Library (which is written in C). They also include adaptive time-stepping.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.