File Exchange

image thumbnail

Lagrange's equations

version 1.0 (1.89 KB) by

Lagrange is a function that calculate equations of motion (Lagrange's equations)

12 Ratings



No License

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.

Comments and Ratings (14)

Nicu Morosan

Nicu Morosan

Great code, but how do I have to write the equation of system composed for example by a mass, a damper, a spring and an external force?
T = m/2*dx^2; %kinetic energy
D = c/2*dx^2; %dissipative
V = k/2*x^2; %elastic
L = F*x; %external force
How do I have to insert them inside? I tried Lag = T + D - V - T but there are some issues.

Alex R

Alex R (view profile)

Good job! Thank you!

Huina Mao

Excellent job!!!

Ismet Handzic

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.


Robin (view profile)

a g is missing at this row in the code:
16 % syms x dx ddx t m g


Gray Thomas

This code worked exactly the way I expected it to. It is totally deserving of the original rating, in my opinion.


Daniel (view profile)

very nice work with symbolic toolbox!

Hrishi Shah

Hrishi Shah (view profile)

Nice code. easy to understand. would be great if you could extend it to include the torque and moment terms too.

John D'Errico

John D'Errico (view profile)

Don't rate your own code. Obviously you think your own stuff is good.


Ivanovich (view profile)

MATLAB Release
MATLAB 7.4 (R2007a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video