GuidedLaunch2DSim:

--------------------------------------------------------------------------
   Simulates a 2D guided launch with the specified payload mass. 
 
   Called from GuidedLaunch2DCost and LaunchGUI. See GuidedLaunch2DRHS for
   information on the dynamic model and LaunchOptions for further
   documentation of the data structure. The simulation is terminated when
   either the altitude or final fuel mass is zero.

   For a direct launch, all stages follow a gravity turn. For an indirect
   launch, the first stage always follows a gravity turn and the last stage
   always follows a fixed control angle with the intermediate stages as
   follows:
      3 stages: 1) and 2) gravity turn, 3) fixed angle
      4 stages: 1) and 2) gravity turn, 3) horizontal, 4) fixed angle

   Uses ode45 for the integration.

   Since version 1.0
--------------------------------------------------------------------------
   Form:
   [time,xTraj,d] = GuidedLaunch2DSim( params, d )
--------------------------------------------------------------------------

   ------
   Inputs
   ------
   params       (3,1)  Initial guess at parameters.
                        1) initial flight path angle (rad)
                        2) mass of last (solid) stage (%)
                        3) coast time before last stage (min), direct
                            OR thrust angle for last stage (rad), indirect
   d             (.)   Data structure including launch vehicle model data
                        .rocket  (.)    Rocket data
                        .rhsFun   ()    Function handle (GuidedLaunch2DRHS)
                        .fControl {}    Array of function handles
                        .mDes   (1,1)   Desired payload mass (kg)
                        .direct (1,1)   Direct flag
                        .h0     (1,1)   Initial altitude
                        .v0     (1,1)   Initial velocity         

   -------
   Outputs
   -------
   time       (nt,1)   Time vector (sec)
   xTraj      (nt,ns)  State vector (output of ode45)
                       [range altitude velocity FPA mSP alpha]
   d           (.)     Data structure supplied to RHS

--------------------------------------------------------------------------

Children:

LaunchVehicle: VehicleModels/SetPayloadMass