% MotionGenesis file: RigidBodyPendulumDynamicsKaneLagrange.txt % Copyright (c) 2009 Motion Genesis LLC. All rights reserved. %---------------------------------------------------------------- NewtonianFrame N % Earth. RigidBody A % Rod. %---------------------------------------------------------------- Variable theta'' % Angle and 1st/2nd time-derivatives. Constant g = 9.8 m/s^2 Constant L = 7.5 cm A.SetMassInertia( m = 10 grams, IAx, IAy, I = 50 g*cm^2 ) %---------------------------------------------------------------- % Rotational and translational kinematics. A.RotateZ( N, theta ) Acm.Translate( No, -L*Ay> ) %---------------------------------------------------------------- % Add relevant forces. Acm.AddForce( -m*g*Ny> ) %---------------------------------------------------------------- % Kane's equation of motion. SetGeneralizedSpeed( theta' ) KaneDynamics = System.GetDynamicsKane() %---------------------------------------------------------------- % Lagrange's equation of motion. SetGeneralizedCoordinate( theta ) PE = System.GetForceGravityPotentialEnergy( -g*Ny>, No ) LagrangeDynamics = System.GetDynamicsLagrange( SystemPotential = PE ) %--------------------------------------------------------------- % Check conservation of kinetic and potential energy. KE = System.GetKineticEnergy() MechanicalEnergy = KE + PE %---------------------------------------------------------------- % Integration parameters and initial values. Input tFinal = 4 sec, tStep = 0.02 sec, absError = 1.0E-07 Input theta = 90 deg, theta' = 0.0 rad/sec %---------------------------------------------------------------- % List output quantities and solve ODEs. Output t seconds, theta degrees, MechanicalEnergy Joules ODE( KaneDynamics = 0, theta'' ) %---------------------------------------------------------------- Save RigidBodyPendulumDynamicsKaneLagrange.html if( LagrangeDynamics[1] == KaneDynamics[1] ) { Quit }