BabybootWithKaneLagrange.html  (MotionGenesis input/output).
```   (1) % MotionGenesis file:  BabybootWithKaneLagrange.txt
(2) % Problem: Analysis of 3D chaotic double pendulum.
(4) %----------------------------------------------------------------
(5) SetDigits( 5 )     % Number of digits displayed for numbers
(6) %----------------------------------------------------------------
(7) NewtonianFrame N
(8) RigidBody      A             % Upper rod
(9) RigidBody      B             % Lower plate
(10) %----------------------------------------------------------------
(11) Variable   qA''              % Pendulum angle and its time-derivatives
(12) Variable   qB''              % Plate angle and its time-derivative
(13) Constant   LA = 7.5 cm       % Distance from pivot to A's mass center
(14) Constant   LB = 20 cm        % Distance from pivot to B's mass center
(15) Constant   g = 9.81 m/s^2    % Earth's gravitational acceleration.
(16) A.SetMassInertia( mA =  10 grams,  IAx = 50 g*cm^2,  IAy,  IAz )
(17) B.SetMassInertia( mB = 100 grams,  IBx = 2500 g*cm^2, IBy = 500 g*cm^2, IBz = 2000 g*cm^2 )
(18) %----------------------------------------------------------------
(19) %       Rotational and translational kinematics.
(20) A.RotateX( N, qA )
-> (21) A_N = [1, 0, 0;  0, cos(qA), sin(qA);  0, -sin(qA), cos(qA)]
-> (22) w_A_N> = qA'*Ax>
-> (23) alf_A_N> = qA''*Ax>

(24) B.RotateZ( A, qB )
-> (25) B_A = [cos(qB), sin(qB), 0;  -sin(qB), cos(qB), 0;  0, 0, 1]
-> (26) w_B_A> = qB'*Bz>
-> (27) w_B_N> = cos(qB)*qA'*Bx> - sin(qB)*qA'*By> + qB'*Bz>
-> (28) alf_B_A> = qB''*Bz>
-> (29) alf_B_N> = (cos(qB)*qA''-sin(qB)*qA'*qB')*Bx> + (-cos(qB)*qA'*qB'-sin(
qB)*qA'')*By> + qB''*Bz>

(30) Acm.Translate( No, -LA*Az> )
-> (31) p_No_Acm> = -LA*Az>
-> (32) v_Acm_N> = LA*qA'*Ay>
-> (33) a_Acm_N> = LA*qA''*Ay> + LA*qA'^2*Az>

(34) Bcm.Translate( No, -LB*Az> )
-> (35) p_No_Bcm> = -LB*Az>
-> (36) v_Bcm_N> = LB*qA'*Ay>
-> (37) a_Bcm_N> = LB*qA''*Ay> + LB*qA'^2*Az>

(38) %-----------------------------------------------------------
-> (41) Force_Acm> = -mA*g*Nz>
-> (42) Force_Bcm> = -mB*g*Nz>

(43) %----------------------------------------------------------------
(44) %       D'Alembert's equations of motion (MG road-maps).
(45) Dynamics[1] = Dot( Ax>,  System(A,B).GetDynamics(No)  )
-> (46) Dynamics[1] = g*(mA*LA+mB*LB)*sin(qA) + IAx*qA'' + mA*LA^2*qA'' + mB*LB^2*qA''
+ IBy*sin(qB)^2*qA'' + cos(qB)*(2*IBy*sin(qB)*qA'*qB'-IBx*(2*sin(qB)*
qA'*qB'-cos(qB)*qA''))

(47) Dynamics[2] = Dot( Bz>,  B.GetDynamics(Bcm)  )
-> (48) Dynamics[2] = (IBx-IBy)*sin(qB)*cos(qB)*qA'^2 + IBz*qB''

(49) %-----------------------------------------------------------
(50) %       Kane's equations of motion (uses generalized speeds).
(51) SetGeneralizedSpeed( qA', qB' )
(52) Dynamics := System.GetDynamicsKane()
-> (53) Dynamics[1] = g*(mA*LA+mB*LB)*sin(qA) + (IAx+IBx+mA*LA^2+mB*LB^2-(IBx-
IBy)*sin(qB)^2)*qA'' - 2*(IBx-IBy)*sin(qB)*cos(qB)*qA'*qB'

-> (54) Dynamics[2] = (IBx-IBy)*sin(qB)*cos(qB)*qA'^2 + IBz*qB''

(55) %-----------------------------------------------------------
(56) %       Kinetic and potential energy.
(57) KE = System.GetKineticEnergy()
-> (58) KE = 0.5*IAx*qA'^2 + 0.5*IBx*qA'^2 + 0.5*IBz*qB'^2 + 0.5*mA*LA^2*qA'^2
+ 0.5*mB*LB^2*qA'^2 - 0.5*(IBx-IBy)*sin(qB)^2*qA'^2

(59) PE = System.GetForceGravityPotentialEnergy( -g*Nz>, No )
-> (60) PE = -g*(mA*LA+mB*LB)*cos(qA)

(61) Energy = KE + PE
-> (62) Energy = PE + KE

(63) %-----------------------------------------------------------
(64) %       Lagranges's equations of motion (uses generalized coordinates).
(65) SetGeneralizedCoordinates( qA, qB )
(66) Dynamics := System.GetDynamicsLagrange( SystemPotential = PE )
-> (67) Dynamics[1] = g*(mA*LA+mB*LB)*sin(qA) + (IAx+IBx+mA*LA^2+mB*LB^2-(IBx-
IBy)*sin(qB)^2)*qA'' - 2*(IBx-IBy)*sin(qB)*cos(qB)*qA'*qB'

-> (68) Dynamics[2] = (IBx-IBy)*sin(qB)*cos(qB)*qA'^2 + IBz*qB''

(69) Solve( Dynamics = 0,  qA'',  qB'' )
-> (70) qA'' = -(g*(mA*LA+mB*LB)*sin(qA)-2*(IBx-IBy)*sin(qB)*cos(qB)*qA'*qB')/(
IAx+IBx+mA*LA^2+mB*LB^2-(IBx-IBy)*sin(qB)^2)

-> (71) qB'' = -(IBx-IBy)*sin(qB)*cos(qB)*qA'^2/IBz

(72) %-----------------------------------------------------------
(73) %       Integration parameters and initial values.
(74) Input  tFinal = 10 sec,  tStep = 0.02 sec,  absError = 1.0E-07,  relError = 1.0E-07
(75) Input  qA = 90 deg,  qA' = 0.0 rad/sec,  qB = 1.0 deg,  qB' = 0.0 rad/sec
(76) %-----------------------------------------------------------
(77) %       List output quantities and solve ODEs.
(78) OutputPlot  t sec,  qA deg,  qB deg,  Energy N*m
(79) ODE()  Babyboot

(80) %------------------------------------------------------------
(81) %       Record input together with responses
```