image thumbnail

Euler-Lagrange tool package

version 1.5.0.0 (75.4 KB) by Mischa Kim
Use the Euler-Lagrange equation to derive differential equations

4.6K Downloads

Updated 24 Oct 2016

View License

Use the Euler-Lagrange tool to derive differential equations based on the system Lagrangian. The Lagrangian is defined symbolically in terms of the generalized coordinates and velocities, and the system parameters. Additional inputs are the vector of generalized forces and a Rayleigh-type dissipation function.

The function returns the vector field description of the differential equations and the associated MATLAB function and Simulink block. The MATLAB function and Simulink block are readily available in a form to be used with e.g. ode45 or in a Simulink model.

To check out the exact syntax and function definition type

>> help eulerlagrange

at the MATLAB command prompt, copy-paste one of the examples into the command window, and execute. As an example:

syms th thd g m l k
L = m*l^2*thd^2/2 + m*g*l*cos(th); % Lagrangian
X = {th thd}; % Vector of generalized coordinates
Q_i = {0}; Q_e = {0}; % No generalized forces
R = k*thd^2/2; % Friction term
par = {g m l k}; % System parameters
% Create symbolic differential equations …
% …and the corresponding 'm'ATLAB function and 's'imulink block
VF = EulerLagrange(L,X,Q_i,Q_e,R,par,'m','s');

Included in the tool package are two ready-made demos, a pendulum and an inverted rotary pendulum system. The pendulum demo shows the usage of the Euler-Lagrange tool from beginning to end. The rotary system is illustrated with a MATLAB and a Simulink demo. If the Simulink 3D Animation toolbox is available the system dynamics can be visualized in a VR world.

Note: Only MATLAB and the Symbolic Math Toolbox are required to use the tool. Simulink, Simulink 3D Animation, and the Aerospace blockset are recommended to run the demos with all the bells and whistles.

Compatibility: This function has been successfully tested with the following releases
- R2013a
- R2014a through R2016b

Cite As

Mischa Kim (2021). Euler-Lagrange tool package (https://www.mathworks.com/matlabcentral/fileexchange/49796-euler-lagrange-tool-package), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2016b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!