lagrange_eq(T,V,Q,F​0,r_F,fun_name,vara​rgin)

Version 2.0.0.0 (3.1 KB) by Manuel
Lagrange equation of motion
231 Downloads
Updated 17 Dec 2015

View License

% lagrange_eq is a function that calculate equations of motion (Lagrange's
% equations) and create a function file to uses with Matlab ode functions.
% The Lagrangian L is separated in T and V, L= T - V, and adds dissipation
% function Q (viscous damper) and generalized force:
% d/dt(dT/d(dq) + dV/dq + dQ/d(dq) = F0
% Symbolic Math Toolbox is required.
%
%
% Usage as:
% lagrange_eq(T,V,Q,F0,r_F,fun_name,q1,q2,...,qn)
%
% T = Kinetic Energy
% V = Potencial Energy
% Q = Dissipated Energy
% F0 = Generalized Force
% r_F = point of force aplication
% fun_name = name of the ode function fun_name.m
% q1 = firts DOF
% q2 = second DOF
% qn = last DOF
%
% T, V, Q, F0 are symbolics functions, q1,q2,..,qn are time-dependent
%
% ******* Example 1 *********
% Mass-Spring-Damper
% 1 DOF
% syms x(t) t m k c f omega
% T = 1/2*m*diff(x)^2;
% V = 1/2*k*x^2;
% Q = 1/2*c*diff(x)^2;
% F = f*sin(omega*t);
% r_F = x(t);
%
% lagrange_eq(T,V,Q,F,'fun_mass_spring_damper',x)
% m = 10; % [kg]
% k = 10; % [N/m]
% c = 100; % [Ns/m]
% f = 50; % [N]
% omega = 10*2*pi; % [rad/s]
%
% [t,x]=ode45(@(t,z) fun_mass_spring_damper(t,z,c,f,k,m,omega) , [0 T_r] , [Xo;DXo]);
%
% ******* Example 2 *********
%
% 2 DOF
% syms x(t) y(t) t m k c f omega
% T =...;
% V =...;
% Q =...;
% F = [f*cos(omega) f*sin(omega)];
% r_F = [x(t) y(t)];
%
% lagrange_eq(T,V,Q,F,r_F,'fun2',x,y)
%
% ******* Example 3 *********
% 5 DOF
% syms q1(t) q2(t) q3(t) q4(t) q5(t) t m k c f omega
% T =...;
% V =...;
% Q =...;
% F =...;
% r_F = ...;
% lagrange_eq(T,V,Q,F,r_F,'fun2',q1,q2,q3,q4,q5)

Cite As

Manuel (2024). lagrange_eq(T,V,Q,F0,r_F,fun_name,varargin) (https://www.mathworks.com/matlabcentral/fileexchange/50936-lagrange_eq-t-v-q-f0-r_f-fun_name-varargin), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Symbolic Math Toolbox in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
2.0.0.0

Added the force calculation

1.0.0.0