RigidBodyPendulumDynamicsFBD.html  (MotionGenesis input/output).
   (1) % MotionGenesis file:  RigidBodyPendulumDynamicsFBD.txt
   (2) % Copyright (c) 2009 Motion Genesis LLC.  All rights reserved.
   (3) %----------------------------------------------------------------
   (4) NewtonianFrame  N            % Earth.
   (5) RigidBody       A            % Rod.
   (6) %----------------------------------------------------------------
   (7) Variable   theta''           % Angle and 1st/2nd time-derivatives.
   (8) Constant   g = 9.8 m/s^2  
   (9) Constant   L = 7.5 cm  
   (10) A.SetMassInertia( m = 10 grams,  IAx,  IAy,  I = 50 g*cm^2 )
   (11) %----------------------------------------------------------------
   (12) %       Rotational and translational kinematics.
   (13) A.RotateZ( N, theta )
-> (14) A_N = [cos(theta), sin(theta), 0;  -sin(theta), cos(theta), 0;  0, 0, 1]
-> (15) w_A_N> = theta'*Az>
-> (16) alf_A_N> = theta''*Az>

   (17) Acm.Translate( No, -L*Ay> )
-> (18) p_No_Acm> = -L*Ay>
-> (19) v_Acm_N> = L*theta'*Ax>
-> (20) a_Acm_N> = L*theta''*Ax> + L*theta'^2*Ay>

   (21) %----------------------------------------------------------------
   (22) %       Add relevant forces.
   (23) Acm.AddForce( -m*g*Ny> )
-> (24) Force_Acm> = -m*g*Ny>

   (25) %----------------------------------------------------------------
   (26) %       Rotational equation of motion.
   (27) Dynamics = Dot(  Nz>,   A.GetDynamics(No)  )
-> (28) Dynamics = m*g*L*sin(theta) + I*theta'' + m*L^2*theta''

   (29) Solve( Dynamics,  theta'' )
-> (30) theta'' = -m*g*L*sin(theta)/(I+m*L^2)

   (31) %---------------------------------------------------------------
   (32) %       Check conservation of kinetic and potential energy.
   (33) KE = System.GetKineticEnergy()
-> (34) KE = 0.5*(I+m*L^2)*theta'^2

   (35) PE = System.GetForceGravityPotentialEnergy( -g*Ny>, No )
-> (36) PE = -m*g*L*cos(theta)

   (37) MechanicalEnergy = KE + PE
-> (38) MechanicalEnergy = PE + KE

   (39) %----------------------------------------------------------------
   (40) %       Integration parameters and initial values.
   (41) Input  tFinal = 4 sec,  tStep  = 0.02 sec,  absError = 1.0E-07
   (42) Input  theta = 90 deg,  theta' = 0.0 rad/sec
   (43) %----------------------------------------------------------------
   (44) %       List output quantities and solve ODEs.
   (45) Output  t seconds,  theta degrees,  MechanicalEnergy Joules
   (46) ODE()

   (47) %----------------------------------------------------------------
Saved by Motion Genesis LLC.   Portions copyright (c) 2009-2017 Motion Genesis LLC. Rights reserved. Only for use with MotionGenesis.