MGBaseballTrajectoryFma.html   (MotionGenesis input/output).
```   (1) % MotionGenesis file:  MGBaseballTrajectoryFma.txt
(3) %--------------------------------------------------------------------
(4) SetUnitSystem   lbm, ft, sec      % Set default units to US units (not SI units).
(5) NewtonianFrame  N                 % Earth (baseball park).
(6) Particle        Q                 % Baseball.
(7) %--------------------------------------------------------------------
(8) Variable  x'',  y''               % Ball's horizontal and vertical measures.
(9) Constant  g = 32.2 ft/s^2         % Gravity (Earth = 9.8 m/s^2,  Moon = 1.7 m/s^2).
(10) Constant  rho = 0.075 lbm/ft^3    % Density of air at sea level (1.2 kg/m^3).
(11) Constant  r = 1.44 inches         % Ball's radius (3.66 cm).
(12) Constant  coefDrag = 0.5 noUnits  % Ball's coefficient of drag.
(13) Q.SetMass( m = 5 ozm )
(14) %--------------------------------------------------------------------
(15) %   Translational kinematics (position, velocity, acceleration).
(16) Q.Translate( No,  x*Nx> + y*Ny> )
-> (17) p_No_Q> = x*Nx> + y*Ny>
-> (18) v_Q_N> = x'*Nx> + y'*Ny>
-> (19) a_Q_N> = x''*Nx> + y''*Ny>

(20) %--------------------------------------------------------------------
(21) %   Add relevant forces (aerodynamic and gravity).
(22) v> = Q.GetVelocity( N )
-> (23) v> = x'*Nx> + y'*Ny>

(24) vMag = GetMagnitude( v> )
-> (25) vMag = sqrt(x'^2+y'^2)

(26) Area = pi*r^2
-> (27) Area = pi*r^2

(28) DragForce> = -1/2 * rho * Area * coefDrag * vMag * v>
-> (29) DragForce> = -0.5*coefDrag*rho*Area*x'*vMag*Nx> - 0.5*coefDrag*rho*Area
*y'*vMag*Ny>

(30) Q.AddForce( DragForce> - m*g*Ny> )
-> (31) Force_Q> = -0.5*coefDrag*rho*Area*x'*vMag*Nx> + (-m*g-0.5*coefDrag*rho*
Area*y'*vMag)*Ny>

(32) %---------------------------------------------------------------------
(33) %   Form equations of motion with F = m*a.
(34) DynamicsNewton[1] = Dot( Nx>,  Q.GetDynamics() )
-> (35) DynamicsNewton[1] = 0.5*coefDrag*rho*Area*x'*vMag + m*x''

(36) DynamicsNewton[2] = Dot( Ny>,  Q.GetDynamics() )
-> (37) DynamicsNewton[2] = m*g + 0.5*coefDrag*rho*Area*y'*vMag + m*y''

(38) %---------------------------------------------------------------------
(39) %   Advanced: Verify dynamics equations with Kane's method.
(40) SetGeneralizedSpeed( x', y' )
(41) DynamicsKane = System.GetDynamicsKane()
-> (42) DynamicsKane = [0.5*coefDrag*rho*Area*x'*vMag + m*x'';  m*g + 0.5*coefDrag*rho*Area*y'*vMag + m*y'']

(43) isSameDynamics = IsSimplifyEqual( DynamicsNewton, DynamicsKane )
-> (44) isSameDynamics = true

(45) %---------------------------------------------------------------------
(46) %   Solve dynamics equations for x'' and  y''.
(47) Solve( DynamicsNewton = 0,   x'',  y''  )
-> (48) x'' = -0.5*coefDrag*rho*Area*x'*vMag/m
-> (49) y'' = -g - 0.5*coefDrag*rho*Area*y'*vMag/m

(50) %--------------------------------------------------------------------
(51) %   Input integration parameters and initial values.
(52) Input  tFinal = 4.6 sec,  tStep = 0.01 sec,  absError = 1.0E-7
(53) Input  x = 0 ft,  x' = 100 * cosDegrees(30) mph
(54) Input  y = 0 ft,  y' = 100 * sinDegrees(30) mph
(55) %--------------------------------------------------------------------
(56) %       List output quantities and solve ODEs.
(57) Output  t sec,  x ft,  y ft,  x' mph,  y' mph,  vMag mph
(58) ODE()  MGBaseballTrajectoryFma

(59) %--------------------------------------------------------------------
```