MGMetronomePendulumEulerLagrangeKane.html  (MotionGenesis input/output).
   (1) % MotionGenesis file:  MGMetronomePendulumEulerLagrangeKane.txt
   (2) % Problem:  Equation of motion for two-particle metronome.
   (3) % Copyright (c) 2017 Motion Genesis LLC.  All rights reserved.
   (4) %--------------------------------------------------------------------
   (5) NewtonianFrame N             % Earth with point No at metronome pivot.
   (6) RigidFrame     B             % Metronome rod.
   (7) Particle       Q1, Q2        % Particles fixed at distal ends of B.
   (8) %--------------------------------------------------------------------
   (9) Variable  theta''            % Metronome angle and 1st/2nd derivative.
   (10) Constant  L = 0.2 m          % Distance between point No and Q1.
   (11) Constant  h = 0.1456 m       % Distance between point No and Q2.
   (12) Constant  g = 9.8 m/s^2      % Earth's gravitational acceleration.
   (13) Constant  k = 2 N*m/rad      % Torsional spring constant.
   (14) Q1.SetMass( m1 = 0.1 kg )
   (15) Q2.SetMass( m2 = 0.02 kg )
   (16) %--------------------------------------------------------------------
   (17) %       Rotational and translational kinematics.
   (18) B.RotateNegativeZ( N, theta )
-> (19) B_N = [cos(theta), -sin(theta), 0;  sin(theta), cos(theta), 0;  0, 0, 1]
-> (20) w_B_N> = -theta'*Bz>
-> (21) alf_B_N> = -theta''*Bz>

   (22) Q1.Translate( No, -L*By> )
-> (23) p_No_Q1> = -L*By>
-> (24) v_Q1_N> = -L*theta'*Bx>
-> (25) a_Q1_N> = -L*theta''*Bx> + L*theta'^2*By>

   (26) Q2.Translate( No,  h*By> )
-> (27) p_No_Q2> = h*By>
-> (28) v_Q2_N> = h*theta'*Bx>
-> (29) a_Q2_N> = h*theta''*Bx> - h*theta'^2*By>

   (30) %--------------------------------------------------------------------
   (31) %       Relevant forces and torques.
   (32) System.AddForceGravity( -g*Ny> )
-> (33) Force_Q1> = -m1*g*Ny>
-> (34) Force_Q2> = -m2*g*Ny>

   (35) B.AddTorque( k*theta*Bz> )
-> (36) Torque_B> = k*theta*Bz>

   (37) %--------------------------------------------------------------------
   (38) %       Euler's equation of motion (angular momentum principle about No).
   (39) Euler = Dot( System.GetDynamics(No), -Bz> )
-> (40) Euler = k*theta + g*(m1*L-m2*h)*sin(theta) + m1*L^2*theta'' + m2*h^2*theta''

   (41) Factor( Euler,  theta'', g )
-> (42) Euler = k*theta + g*(m1*L-m2*h)*sin(theta) + (m1*L^2+m2*h^2)*theta''

   (43) %--------------------------------------------------------------------
   (44) %       Conservation of mechanical energy.
   (45) KineticEnergy = System.GetKineticEnergy()
-> (46) KineticEnergy = 0.5*(m1*L^2+m2*h^2)*theta'^2

   (47) PotentialEnergyGravity = System.GetForceGravityPotentialEnergy( -g*Ny>, No )
-> (48) PotentialEnergyGravity = -g*(m1*L-m2*h)*cos(theta)

   (49) PotentialEnergySpring = 1/2 * k * theta^2
-> (50) PotentialEnergySpring = 0.5*k*theta^2

   (51) PotentialEnergy = PotentialEnergyGravity + PotentialEnergySpring
-> (52) PotentialEnergy = PotentialEnergyGravity + PotentialEnergySpring

   (53) MechanicalEnergy = KineticEnergy + PotentialEnergy
-> (54) MechanicalEnergy = PotentialEnergy + KineticEnergy

   (55) %--------------------------------------------------------------------
   (56) %       Lagrange's equation of motion.
   (57) SetGeneralizedCoordinate( theta )
   (58) Lagrange = System.GetDynamicsLagrange( SystemPotential = PotentialEnergy )
-> (59) Lagrange = [k*theta + g*(m1*L-m2*h)*sin(theta) + (m1*L^2+m2*h^2)*theta'']

   (60) Factor( Lagrange,  theta'', g )
-> (61) Lagrange = [k*theta + g*(m1*L-m2*h)*sin(theta) + (m1*L^2+m2*h^2)*theta'']

   (62) %--------------------------------------------------------------------
   (63) %       Kane's equation of motion.
   (64) SetGeneralizedSpeed( theta' )
   (65) Kane = System.GetDynamicsKane()
-> (66) Kane[1] = k*theta + m1*g*L*sin(theta) + (m1*L^2+m2*h^2)*theta'' - m2*g*
        h*sin(theta)

   (67) Factor( Kane,  theta'', g )
-> (68) Kane = [k*theta + g*(m1*L-m2*h)*sin(theta) + (m1*L^2+m2*h^2)*theta'']

   (69) %--------------------------------------------------------------------
   (70) %       Save input and program responses.
Saved by Motion Genesis LLC.   Portions copyright (c) 2009-2017 Motion Genesis LLC. Rights reserved. Only for use with MotionGenesis.