% MotionGenesis file: MGSwingingSpring2DPendulumKaneLagrange.txt % Problem: 2D Pendulum on a swinging spring (coupled nonlinear beat phenomenon). % Copyright (c) 2009 Motion Genesis LLC. All rights reserved. %-------------------------------------------------------------------- NewtonianFrame N % Earth. Particle Q % Particle at end of spring. RigidFrame B % Vector basis with By> directed from Q to No. %-------------------------------------------------------------------- Variable y'' % Spring stretch (from natural length) Variable q'' % Pendulum angle Constant g = 9.8 m/s^2 % Earth's gravitational acceleration Constant k = 100 N/m % Linear spring constant Constant Ln = 0.3 m % Natural length of spring Q.SetMass( m = 1 kg ) %-------------------------------------------------------------------- % Rotational and translational kinematics. B.RotateZ( N, q ) Q.Translate( No, -(Ln+y)*By> ) %-------------------------------------------------------------------- % Add gravity and spring forces to Q. Q.AddForce( -m*g*Ny> + k*y*By> ) %-------------------------------------------------------------------- % Equations of motion with Kane's method. SetGeneralizedSpeeds( q', y' ) DynamicsKane = System.GetDynamicsKane() %-------------------------------------------------------------------- % Kinetic and potential energy (gravity and spring). KineticEnergy = System.GetKineticEnergy() PEGravity = Q.GetForceGravityPotentialEnergy( -g*Ny>, No ) PotentialEnergy = PEGravity + 1/2*k*y^2 TotalEnergy = KineticEnergy + PotentialEnergy %-------------------------------------------------------------------- % Equations of motion with Lagrange's method. SetGeneralizedCoordinates( q, y ) DynamicsLagrange = System.GetDynamicsLagrange( systemPotential = PotentialEnergy ) Solve( DynamicsLagrange, q'', y'' ) %-------------------------------------------------------------------- % Integration parameters and initial values. Input tFinal = 16 sec, tStep = 0.01 sec, absError = 1.0E-07 Input q = 1.0 deg, q'=0 deg/sec, y = 0.2 m, y' = 0 m/s %-------------------------------------------------------------------- % List output quantities and solve ODEs. Output t sec, q deg, y m, TotalEnergy Joules ODE() MGSwingingSpring2DPendulumKaneLagrange %-------------------------------------------------------------------- Save MGSwingingSpring2DPendulumKaneLagrange.html Quit