Lagrange is a function that calculate equations of motion (Lagrange's equations)
d/dt(dL/d(dq))- dL/dq=0.
It Uses the Lagrangian that is a function that summarizes the
dynamics of the system. Symbolic Math Toolbox is required.
Why did you use the simple() and collect() commands in this function? Is it functional? Because it seems to work just as well and much faster without those.