Moon Landing Problem#

The Moon landing problem is a version of the soft landing problem presented in [Med64]. The problem is simplified to have one degree-of-freedom and normalized such that the Moon’s gravity is unity. The goal is to minimize the amount of fuel consumed or, stated differently, maximize the final mass, while bringing the lander down to the surface for a soft landing.

State and control variables#

This system has three state variables, the altitude (\(h\)), velocity (\(v\)), and mass (\(m\)) of the lander.

This system has one control variable, (\(T\)), the thrust applied to the vehicle.

The dynamics of the system are given by

(70)#\[\begin{align} \dot{h} &= v \\ \dot{v} &= -1 + \frac{T}{m} \\ \dot{m} &= -\frac{T}{2.349} \end{align}\]

Problem Definition#

We seek to maximize the final mass of the vehicle while bringing it to a soft landing.

(71)#\[\begin{align} \mathrm{Minimize} \, J &= m_f \end{align}\]

The initial conditions are

(72)#\[\begin{align} h_0 &= 1 \\ v_0 &= -0.783 \\ m_0 &= 1 \end{align}\]

and the terminal constraints are

(73)#\[\begin{align} h_f &= 0 \\ v_f &= 0 \end{align}\]

Additionally, the thrust is constrained to be positive but remain under 1.227.

(74)#\[\begin{align} 0 \le T \le 1.227 \end{align}\]

Defining the ODE#

The following implements the dynamics of the Moon landing problem described above.

import numpy as np
import openmdao.api as om


class MoonLandingProblemODE(om.ExplicitComponent):
    def initialize(self):
        self.options.declare('num_nodes', types=int)

    def setup(self):
        nn = self.options['num_nodes']

        # inputs
        self.add_input('h', val=np.ones(nn), units=None, desc='Altitude')
        self.add_input('v', val=np.ones(nn), units='1/s', desc='Velocity')
        self.add_input('m', val=np.ones(nn), units=None, desc='Mass')
        self.add_input('T', val=np.ones(nn), units=None, desc='Thrust')

        # outputs
        self.add_output('h_dot', val=np.ones(nn), units='1/s', desc='Rate of change of Altitude')
        self.add_output('v_dot', val=np.ones(nn), units='1/s**2', desc='Rate of change of Velocity')
        self.add_output('m_dot', val=np.ones(nn), units='1/s', desc='Rate of change of Mass')

        # partials
        ar = np.arange(nn)
        self.declare_partials(of='h_dot', wrt='v', rows=ar, cols=ar, val=1.0)
        self.declare_partials(of='v_dot', wrt='m', rows=ar, cols=ar)
        self.declare_partials(of='v_dot', wrt='T', rows=ar, cols=ar)
        self.declare_partials(of='m_dot', wrt='T', rows=ar, cols=ar, val=-1/2.349)
        self.declare_partials(of='m_dot', wrt='T', rows=ar, cols=ar, val=-1/2.349)

    def compute(self, inputs, outputs, discrete_inputs=None, discrete_outputs=None):
        v = inputs['v']
        m = inputs['m']
        T = inputs['T']

        outputs['h_dot'] = v
        outputs['v_dot'] = -1 + T/m
        outputs['m_dot'] = -T/2.349

    def compute_partials(self, inputs, partials, discrete_inputs=None):
        m = inputs['m']
        T = inputs['T']

        partials['v_dot', 'T'] = 1/m
        partials['v_dot', 'm'] = -T/m**2

Solving the Moon landing problem with Dymos#

The optimal solution to this problem is known to have bang-bang control. That is, the control has a “jump” that render it discontinuous in time. Capturing this behavior accurately requires the use of grid refinement for the Gauss-Lobatto and Radau pseudospectral transcriptions but the Birkhoff pseudospectral transcription can be used to handle this behavior without the use of any grid refinement. The following code shows the use of the Birkhoff pseudospectral transcription to solve the problem.

import dymos as dm

p = om.Problem(model=om.Group())
p.driver = om.pyOptSparseDriver()
p.driver.declare_coloring()
p.driver.options['optimizer'] = 'IPOPT'
p.driver.opt_settings['hessian_approximation'] = 'limited-memory'
p.driver.opt_settings['print_level'] = 0
p.driver.opt_settings['linear_solver'] = 'mumps'
p.driver.declare_coloring()

t = dm.Birkhoff(num_nodes=20)

traj = p.model.add_subsystem('traj', dm.Trajectory())
phase = dm.Phase(ode_class=MoonLandingProblemODE, transcription=t)

phase.set_time_options(fix_initial=True, fix_duration=False)
phase.add_state('h', fix_initial=True, rate_source='h_dot')
phase.add_state('v', fix_initial=True, rate_source='v_dot')
phase.add_state('m', fix_initial=True, lower=1e-3, rate_source='m_dot')
phase.add_control('T', lower=0.0, upper=1.227)

phase.add_boundary_constraint('h', loc='final', equals=0.0)
phase.add_boundary_constraint('v', loc='final', equals=0.0)

phase.add_objective('m', scaler=-1)
phase.set_simulate_options(atol=1.0E-1, rtol=1.0E-2)

traj.add_phase('phase', phase)

p.setup(check=True, force_alloc_complex=True)

phase.set_time_val(initial=0.0, duration=1.0)
phase.set_state_val('h', [1.0, 0.0])
phase.set_state_val('v', [-0.783, 0.0])
phase.set_state_val('m', [1.0, 0.2])
phase.set_control_val('T', [0.0, 1.227])
dm.run_problem(p, simulate=False, simulate_kwargs={'times_per_seg': 100}, make_plots=True)
INFO: checking out_of_order...
INFO:     out_of_order check complete (0.000312 sec).
INFO: checking system...
INFO:     system check complete (0.000014 sec).
INFO: checking solvers...
INFO:     solvers check complete (0.000156 sec).
INFO: checking dup_inputs...
INFO:     dup_inputs check complete (0.000053 sec).
INFO: checking missing_recorders...
INFO:     missing_recorders check complete (0.000002 sec).
INFO: checking unserializable_options...
INFO:     unserializable_options check complete (0.000977 sec).
INFO: checking comp_has_no_outputs...
INFO:     comp_has_no_outputs check complete (0.000027 sec).
INFO: checking auto_ivc_warnings...
INFO:     auto_ivc_warnings check complete (0.000003 sec).
INFO: checking out_of_order...
INFO:     out_of_order check complete (0.000204 sec).
INFO: checking system...
INFO:     system check complete (0.000013 sec).
INFO: checking solvers...
INFO:     solvers check complete (0.000134 sec).
INFO: checking dup_inputs...
INFO:     dup_inputs check complete (0.000071 sec).
INFO: checking missing_recorders...
INFO:     missing_recorders check complete (0.000002 sec).
INFO: checking unserializable_options...
INFO:     unserializable_options check complete (0.000942 sec).
INFO: checking comp_has_no_outputs...
INFO:     comp_has_no_outputs check complete (0.000025 sec).
INFO: checking auto_ivc_warnings...
INFO:     auto_ivc_warnings check complete (0.000003 sec).
Jacobian shape: (63, 124)  (2.60% nonzero)
FWD solves: 4   REV solves: 0
Total colors vs. total size: 4 vs 124  (96.77% improvement)

Sparsity computed using tolerance: 1e-25.
Dense total jacobian for Problem 'problem' was computed 3 times.
Time to compute sparsity:   0.1060 sec
Time to compute coloring:   0.0729 sec
Memory to compute coloring:   0.3750 MB
Coloring created on: 2025-08-08 20:12:18
Optimization Problem -- Optimization using pyOpt_sparse
================================================================================
    Objective Function: _objfunc

    Solution: 
--------------------------------------------------------------------------------
    Total Time:                    0.5942
       User Objective Time :       0.0179
       User Sensitivity Time :     0.4765
       Interface Time :            0.0460
       Opt Solver Time:            0.0538
    Calls to Objective Function :      16
    Calls to Sens Function :           16


   Objectives
      Index  Name                                  Value
          0  traj.phase.boundary_vals.m    -3.952837E-01

   Variables (c - continuous, i - integer, d - discrete)
      Index  Name                          Type      Lower Bound            Value      Upper Bound     Status
          0  traj.phase.t_duration_0          c    -1.000000E+21     1.397227E+00     1.000000E+21           
          1  traj.phase.controls:T_0          c     0.000000E+00     1.900625E-07     1.227000E+00          l
          2  traj.phase.controls:T_1          c     0.000000E+00     1.200754E-08     1.227000E+00          l
          3  traj.phase.controls:T_2          c     0.000000E+00     2.042712E-09     1.227000E+00          l
          4  traj.phase.controls:T_3          c     0.000000E+00     1.360111E-09     1.227000E+00          l
          5  traj.phase.controls:T_4          c     0.000000E+00     4.448197E-09     1.227000E+00          l
          6  traj.phase.controls:T_5          c     0.000000E+00     4.256705E-01     1.227000E+00           
          7  traj.phase.controls:T_6          c     0.000000E+00     1.227000E+00     1.227000E+00          u
          8  traj.phase.controls:T_7          c     0.000000E+00     1.227000E+00     1.227000E+00          u
          9  traj.phase.controls:T_8          c     0.000000E+00     1.227000E+00     1.227000E+00          u
         10  traj.phase.controls:T_9          c     0.000000E+00     1.227000E+00     1.227000E+00          u
         11  traj.phase.controls:T_10         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         12  traj.phase.controls:T_11         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         13  traj.phase.controls:T_12         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         14  traj.phase.controls:T_13         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         15  traj.phase.controls:T_14         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         16  traj.phase.controls:T_15         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         17  traj.phase.controls:T_16         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         18  traj.phase.controls:T_17         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         19  traj.phase.controls:T_18         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         20  traj.phase.controls:T_19         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         21  traj.phase.states:h_0            c    -1.000000E+30     1.000000E+00     1.000000E+30           
         22  traj.phase.states:h_1            c    -1.000000E+30     9.924938E-01     1.000000E+30           
         23  traj.phase.states:h_2            c    -1.000000E+30     9.696467E-01     1.000000E+30           
         24  traj.phase.states:h_3            c    -1.000000E+30     9.305227E-01     1.000000E+30           
         25  traj.phase.states:h_4            c    -1.000000E+30     8.738058E-01     1.000000E+30           
         26  traj.phase.states:h_5            c    -1.000000E+30     7.982641E-01     1.000000E+30           
         27  traj.phase.states:h_6            c    -1.000000E+30     7.064505E-01     1.000000E+30           
         28  traj.phase.states:h_7            c    -1.000000E+30     6.061256E-01     1.000000E+30           
         29  traj.phase.states:h_8            c    -1.000000E+30     5.024707E-01     1.000000E+30           
         30  traj.phase.states:h_9            c    -1.000000E+30     3.999428E-01     1.000000E+30           
         31  traj.phase.states:h_10           c    -1.000000E+30     3.034069E-01     1.000000E+30           
         32  traj.phase.states:h_11           c    -1.000000E+30     2.170119E-01     1.000000E+30           
         33  traj.phase.states:h_12           c    -1.000000E+30     1.443228E-01     1.000000E+30           
         34  traj.phase.states:h_13           c    -1.000000E+30     8.734397E-02     1.000000E+30           
         35  traj.phase.states:h_14           c    -1.000000E+30     4.664210E-02     1.000000E+30           
         36  traj.phase.states:h_15           c    -1.000000E+30     2.082882E-02     1.000000E+30           
         37  traj.phase.states:h_16           c    -1.000000E+30     7.075257E-03     1.000000E+30           
         38  traj.phase.states:h_17           c    -1.000000E+30     1.469604E-03     1.000000E+30           
         39  traj.phase.states:h_18           c    -1.000000E+30     9.514736E-05     1.000000E+30           
         40  traj.phase.states:h_19           c    -1.000000E+30     6.174501E-17     1.000000E+30           
         41  traj.phase.state_rates:h_0       c    -1.000000E+30    -5.470143E-01     1.000000E+30           
         42  traj.phase.state_rates:h_1       c    -1.000000E+30    -5.536763E-01     1.000000E+30           
         43  traj.phase.state_rates:h_2       c    -1.000000E+30    -5.734247E-01     1.000000E+30           
         44  traj.phase.state_rates:h_3       c    -1.000000E+30    -6.058871E-01     1.000000E+30           
         45  traj.phase.state_rates:h_4       c    -1.000000E+30    -6.500537E-01     1.000000E+30           
         46  traj.phase.state_rates:h_5       c    -1.000000E+30    -6.965069E-01     1.000000E+30           
         47  traj.phase.state_rates:h_6       c    -1.000000E+30    -7.033109E-01     1.000000E+30           
         48  traj.phase.state_rates:h_7       c    -1.000000E+30    -6.772406E-01     1.000000E+30           
         49  traj.phase.state_rates:h_8       c    -1.000000E+30    -6.489352E-01     1.000000E+30           
         50  traj.phase.state_rates:h_9       c    -1.000000E+30    -6.080881E-01     1.000000E+30           
         51  traj.phase.state_rates:h_10      c    -1.000000E+30    -5.594978E-01     1.000000E+30           
         52  traj.phase.state_rates:h_11      c    -1.000000E+30    -4.988972E-01     1.000000E+30           
         53  traj.phase.state_rates:h_12      c    -1.000000E+30    -4.298995E-01     1.000000E+30           
         54  traj.phase.state_rates:h_13      c    -1.000000E+30    -3.521394E-01     1.000000E+30           
         55  traj.phase.state_rates:h_14      c    -1.000000E+30    -2.705403E-01     1.000000E+30           
         56  traj.phase.state_rates:h_15      c    -1.000000E+30    -1.889000E-01     1.000000E+30           
         57  traj.phase.state_rates:h_16      c    -1.000000E+30    -1.143464E-01     1.000000E+30           
         58  traj.phase.state_rates:h_17      c    -1.000000E+30    -5.363801E-02     1.000000E+30           
         59  traj.phase.state_rates:h_18      c    -1.000000E+30    -1.387949E-02     1.000000E+30           
         60  traj.phase.state_rates:h_19      c    -1.000000E+30     8.532001E-19     1.000000E+30           
         61  traj.phase.final_states:h_0      c    -1.000000E+30     0.000000E+00     1.000000E+30           
         62  traj.phase.states:v_0            c    -1.000000E+30    -7.830000E-01     1.000000E+30           
         63  traj.phase.states:v_1            c    -1.000000E+30    -7.925359E-01     1.000000E+30           
         64  traj.phase.states:v_2            c    -1.000000E+30    -8.208041E-01     1.000000E+30           
         65  traj.phase.states:v_3            c    -1.000000E+30    -8.672708E-01     1.000000E+30           
         66  traj.phase.states:v_4            c    -1.000000E+30    -9.304912E-01     1.000000E+30           
         67  traj.phase.states:v_5            c    -1.000000E+30    -9.969847E-01     1.000000E+30           
         68  traj.phase.states:v_6            c    -1.000000E+30    -1.006724E+00     1.000000E+30           
         69  traj.phase.states:v_7            c    -1.000000E+30    -9.694068E-01     1.000000E+30           
         70  traj.phase.states:v_8            c    -1.000000E+30    -9.288902E-01     1.000000E+30           
         71  traj.phase.states:v_9            c    -1.000000E+30    -8.704215E-01     1.000000E+30           
         72  traj.phase.states:v_10           c    -1.000000E+30    -8.008690E-01     1.000000E+30           
         73  traj.phase.states:v_11           c    -1.000000E+30    -7.141249E-01     1.000000E+30           
         74  traj.phase.states:v_12           c    -1.000000E+30    -6.153610E-01     1.000000E+30           
         75  traj.phase.states:v_13           c    -1.000000E+30    -5.040547E-01     1.000000E+30           
         76  traj.phase.states:v_14           c    -1.000000E+30    -3.872532E-01     1.000000E+30           
         77  traj.phase.states:v_15           c    -1.000000E+30    -2.703927E-01     1.000000E+30           
         78  traj.phase.states:v_16           c    -1.000000E+30    -1.636762E-01     1.000000E+30           
         79  traj.phase.states:v_17           c    -1.000000E+30    -7.677782E-02     1.000000E+30           
         80  traj.phase.states:v_18           c    -1.000000E+30    -1.986720E-02     1.000000E+30           
         81  traj.phase.states:v_19           c    -1.000000E+30     1.221277E-18     1.000000E+30           
         82  traj.phase.state_rates:v_0       c    -1.000000E+30    -6.986133E-01     1.000000E+30           
         83  traj.phase.state_rates:v_1       c    -1.000000E+30    -6.986134E-01     1.000000E+30           
         84  traj.phase.state_rates:v_2       c    -1.000000E+30    -6.986134E-01     1.000000E+30           
         85  traj.phase.state_rates:v_3       c    -1.000000E+30    -6.986134E-01     1.000000E+30           
         86  traj.phase.state_rates:v_4       c    -1.000000E+30    -6.986134E-01     1.000000E+30           
         87  traj.phase.state_rates:v_5       c    -1.000000E+30    -3.997705E-01     1.000000E+30           
         88  traj.phase.state_rates:v_6       c    -1.000000E+30     1.930710E-01     1.000000E+30           
         89  traj.phase.state_rates:v_7       c    -1.000000E+30     2.474667E-01     1.000000E+30           
         90  traj.phase.state_rates:v_8       c    -1.000000E+30     3.095485E-01     1.000000E+30           
         91  traj.phase.state_rates:v_9       c    -1.000000E+30     3.864465E-01     1.000000E+30           
         92  traj.phase.state_rates:v_10      c    -1.000000E+30     4.751158E-01     1.000000E+30           
         93  traj.phase.state_rates:v_11      c    -1.000000E+30     5.799643E-01     1.000000E+30           
         94  traj.phase.state_rates:v_12      c    -1.000000E+30     6.980260E-01     1.000000E+30           
         95  traj.phase.state_rates:v_13      c    -1.000000E+30     8.307085E-01     1.000000E+30           
         96  traj.phase.state_rates:v_14      c    -1.000000E+30     9.719486E-01     1.000000E+30           
         97  traj.phase.state_rates:v_15      c    -1.000000E+30     1.116772E+00     1.000000E+30           
         98  traj.phase.state_rates:v_16      c    -1.000000E+30     1.252712E+00     1.000000E+30           
         99  traj.phase.state_rates:v_17      c    -1.000000E+30     1.366703E+00     1.000000E+30           
        100  traj.phase.state_rates:v_18      c    -1.000000E+30     1.442978E+00     1.000000E+30           
        101  traj.phase.state_rates:v_19      c    -1.000000E+30     1.469952E+00     1.000000E+30           
        102  traj.phase.final_states:v_0      c    -1.000000E+30     0.000000E+00     1.000000E+30           
        103  traj.phase.states:m_0            c     1.000000E-03     1.000000E+00     1.000000E+30           
        104  traj.phase.states:m_1            c     1.000000E-03     1.000003E+00     1.000000E+30           
        105  traj.phase.states:m_2            c     1.000000E-03     9.999805E-01     1.000000E+30           
        106  traj.phase.states:m_3            c     1.000000E-03     1.000026E+00     1.000000E+30           
        107  traj.phase.states:m_4            c     1.000000E-03     1.000087E+00     1.000000E+30           
        108  traj.phase.states:m_5            c     1.000000E-03     9.951016E-01     1.000000E+30           
        109  traj.phase.states:m_6            c     1.000000E-03     9.613252E-01     1.000000E+30           
        110  traj.phase.states:m_7            c     1.000000E-03     9.060529E-01     1.000000E+30           
        111  traj.phase.states:m_8            c     1.000000E-03     8.502589E-01     1.000000E+30           
        112  traj.phase.states:m_9            c     1.000000E-03     7.900012E-01     1.000000E+30           
        113  traj.phase.states:m_10           c     1.000000E-03     7.303206E-01     1.000000E+30           
        114  traj.phase.states:m_11           c     1.000000E-03     6.704314E-01     1.000000E+30           
        115  traj.phase.states:m_12           c     1.000000E-03     6.137581E-01     1.000000E+30           
        116  traj.phase.states:m_13           c     1.000000E-03     5.605090E-01     1.000000E+30           
        117  traj.phase.states:m_14           c     1.000000E-03     5.131199E-01     1.000000E+30           
        118  traj.phase.states:m_15           c     1.000000E-03     4.721855E-01     1.000000E+30           
        119  traj.phase.states:m_16           c     1.000000E-03     4.392904E-01     1.000000E+30           
        120  traj.phase.states:m_17           c     1.000000E-03     4.150448E-01     1.000000E+30           
        121  traj.phase.states:m_18           c     1.000000E-03     4.002624E-01     1.000000E+30           
        122  traj.phase.states:m_19           c     1.000000E-03     3.952837E-01     1.000000E+30           
        123  traj.phase.state_rates:m_0       c    -1.000000E+30    -5.651950E-08     1.000000E+30           
        124  traj.phase.state_rates:m_1       c    -1.000000E+30    -3.570203E-09     1.000000E+30           
        125  traj.phase.state_rates:m_2       c    -1.000000E+30    -6.070162E-10     1.000000E+30           
        126  traj.phase.state_rates:m_3       c    -1.000000E+30    -4.040443E-10     1.000000E+30           
        127  traj.phase.state_rates:m_4       c    -1.000000E+30    -1.322227E-09     1.000000E+30           
        128  traj.phase.state_rates:m_5       c    -1.000000E+30    -1.265982E-01     1.000000E+30           
        129  traj.phase.state_rates:m_6       c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        130  traj.phase.state_rates:m_7       c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        131  traj.phase.state_rates:m_8       c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        132  traj.phase.state_rates:m_9       c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        133  traj.phase.state_rates:m_10      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        134  traj.phase.state_rates:m_11      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        135  traj.phase.state_rates:m_12      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        136  traj.phase.state_rates:m_13      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        137  traj.phase.state_rates:m_14      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        138  traj.phase.state_rates:m_15      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        139  traj.phase.state_rates:m_16      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        140  traj.phase.state_rates:m_17      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        141  traj.phase.state_rates:m_18      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        142  traj.phase.state_rates:m_19      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        143  traj.phase.final_states:m_0      c    -1.000000E+30     3.952837E-01     1.000000E+30           

   Constraints (i - inequality, e - equality)
      Index  Name                            Type          Lower           Value           Upper    Status  Lagrange Multiplier
          0  traj.phase.h[final]                e   0.000000E+00    0.000000E+00    0.000000E+00               1.13275E-01
          1  traj.phase.v[final]                e   0.000000E+00    0.000000E+00    0.000000E+00              -2.48458E-01
          2  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               0.00000E+00
          3  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               3.36609E-13
          4  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               1.46395E-12
          5  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               3.16692E-12
          6  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               5.73159E-12
          7  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               8.61545E-12
          8  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               1.06130E-11
          9  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               1.17597E-11
         10  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               1.09475E-11
         11  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               1.04024E-11
         12  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               7.14695E-12
         13  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               5.81826E-12
         14  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               2.61522E-12
         15  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               1.48612E-12
         16  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               3.54580E-13
         17  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00              -2.40215E-13
         18  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               3.84118E-14
         19  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00              -1.50650E-13
         20  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               2.72450E-15
         21  traj.phase.state_defects:h         e   1.000000E+00    1.000000E+00    1.000000E+00               6.34097E-18
         22  traj.phase.state_defects:h         e  -1.000000E+00   -1.000000E+00   -1.000000E+00               1.13275E-01
         23  traj.phase.state_rate_defects:h    e   0.000000E+00    1.110223E-16    0.000000E+00              -3.13782E-04
         24  traj.phase.state_rate_defects:h    e   0.000000E+00   -7.360779E-14    0.000000E+00              -3.00987E-03
         25  traj.phase.state_rate_defects:h    e   0.000000E+00   -6.938894E-14    0.000000E+00              -6.10670E-03
         26  traj.phase.state_rate_defects:h    e   0.000000E+00   -1.553202E-13    0.000000E+00              -8.90228E-03
         27  traj.phase.state_rate_defects:h    e   0.000000E+00   -2.114975E-13    0.000000E+00              -1.15108E-02
         28  traj.phase.state_rate_defects:h    e   0.000000E+00   -2.492451E-13    0.000000E+00              -1.37757E-02
         29  traj.phase.state_rate_defects:h    e   0.000000E+00   -7.283063E-14    0.000000E+00              -1.56825E-02
         30  traj.phase.state_rate_defects:h    e   0.000000E+00   -7.693846E-14    0.000000E+00              -1.71505E-02
         31  traj.phase.state_rate_defects:h    e   0.000000E+00   -9.103829E-15    0.000000E+00              -1.81575E-02
         32  traj.phase.state_rate_defects:h    e   0.000000E+00   -2.775558E-14    0.000000E+00              -1.86654E-02
         33  traj.phase.state_rate_defects:h    e   0.000000E+00    5.773160E-15    0.000000E+00              -1.86654E-02
         34  traj.phase.state_rate_defects:h    e   0.000000E+00   -6.550316E-15    0.000000E+00              -1.81575E-02
         35  traj.phase.state_rate_defects:h    e   0.000000E+00    2.720046E-15    0.000000E+00              -1.71505E-02
         36  traj.phase.state_rate_defects:h    e   0.000000E+00   -1.054712E-15    0.000000E+00              -1.56825E-02
         37  traj.phase.state_rate_defects:h    e   0.000000E+00   -9.936496E-15    0.000000E+00              -1.37757E-02
         38  traj.phase.state_rate_defects:h    e   0.000000E+00   -4.773959E-15    0.000000E+00              -1.15108E-02
         39  traj.phase.state_rate_defects:h    e   0.000000E+00   -2.364775E-14    0.000000E+00              -8.90228E-03
         40  traj.phase.state_rate_defects:h    e   0.000000E+00   -7.639722E-15    0.000000E+00              -6.10670E-03
         41  traj.phase.state_rate_defects:h    e   0.000000E+00   -2.470940E-14    0.000000E+00              -3.00987E-03
         42  traj.phase.state_rate_defects:h    e   0.000000E+00   -1.125750E-25    0.000000E+00              -3.13782E-04
         43  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -2.19212E-04
         44  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -2.10273E-03
         45  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -4.26623E-03
         46  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -6.21925E-03
         47  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -8.04161E-03
         48  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -9.62391E-03
         49  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -1.09560E-02
         50  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -1.19816E-02
         51  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -1.26850E-02
         52  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -1.30399E-02
         53  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -1.30399E-02
         54  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -1.26850E-02
         55  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -1.19816E-02
         56  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -1.09560E-02
         57  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -9.62391E-03
         58  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -8.04161E-03
         59  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -6.21925E-03
         60  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -4.26623E-03
         61  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -2.10273E-03
         62  traj.phase.state_defects:v         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              -2.19212E-04
         63  traj.phase.state_defects:v         e   7.830000E-01    7.830000E-01    7.830000E-01              -2.48458E-01
         64  traj.phase.state_rate_defects:v    e   0.000000E+00   -1.593481E-11    0.000000E+00               2.48535E-04
         65  traj.phase.state_rate_defects:v    e   0.000000E+00   -3.216982E-12    0.000000E+00               2.42763E-03
         66  traj.phase.state_rate_defects:v    e   0.000000E+00   -1.696532E-12    0.000000E+00               5.09056E-03
         67  traj.phase.state_rate_defects:v    e   0.000000E+00   -2.151168E-12    0.000000E+00               7.83991E-03
         68  traj.phase.state_rate_defects:v    e   0.000000E+00   -3.867795E-12    0.000000E+00               1.08577E-02
         69  traj.phase.state_rate_defects:v    e   0.000000E+00    4.052036E-12    0.000000E+00               1.40762E-02
         70  traj.phase.state_rate_defects:v    e   0.000000E+00    1.224437E-12    0.000000E+00               1.74470E-02
         71  traj.phase.state_rate_defects:v    e   0.000000E+00    5.513923E-13    0.000000E+00               2.08260E-02
         72  traj.phase.state_rate_defects:v    e   0.000000E+00    2.658429E-13    0.000000E+00               2.40249E-02
         73  traj.phase.state_rate_defects:v    e   0.000000E+00    1.875722E-13    0.000000E+00               2.68266E-02
         74  traj.phase.state_rate_defects:v    e   0.000000E+00    1.424416E-13    0.000000E+00               2.89751E-02
         75  traj.phase.state_rate_defects:v    e   0.000000E+00    1.013634E-13    0.000000E+00               3.02581E-02
         76  traj.phase.state_rate_defects:v    e   0.000000E+00    9.647838E-14    0.000000E+00               3.04468E-02
         77  traj.phase.state_rate_defects:v    e   0.000000E+00    6.650236E-14    0.000000E+00               2.94369E-02
         78  traj.phase.state_rate_defects:v    e   0.000000E+00    6.783463E-14    0.000000E+00               2.71073E-02
         79  traj.phase.state_rate_defects:v    e   0.000000E+00    7.438494E-14    0.000000E+00               2.35547E-02
         80  traj.phase.state_rate_defects:v    e   0.000000E+00    9.992007E-14    0.000000E+00               1.87741E-02
         81  traj.phase.state_rate_defects:v    e   0.000000E+00    2.537970E-13    0.000000E+00               1.31659E-02
         82  traj.phase.state_rate_defects:v    e   0.000000E+00    7.103207E-13    0.000000E+00               6.57058E-03
         83  traj.phase.state_rate_defects:v    e   0.000000E+00    9.912959E-12    0.000000E+00               6.89538E-04
         84  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -2.29905E-11
         85  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -9.99561E-12
         86  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00               2.07475E-12
         87  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00               6.32824E-12
         88  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -2.17041E-11
         89  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -4.22729E-03
         90  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -1.61831E-02
         91  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -2.17460E-02
         92  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -2.84867E-02
         93  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -3.68461E-02
         94  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -4.65671E-02
         95  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -5.77051E-02
         96  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -6.92832E-02
         97  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -8.03172E-02
         98  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -8.82531E-02
         99  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -9.05596E-02
        100  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -8.33944E-02
        101  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -6.55150E-02
        102  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -3.51557E-02
        103  traj.phase.state_defects:m         e   1.000000E+00    1.000000E+00    1.000000E+00              -3.78287E-03
        104  traj.phase.state_defects:m         e  -1.000000E+00   -1.000000E+00   -1.000000E+00              -1.00000E+00
        105  traj.phase.state_rate_defects:m    e   0.000000E+00    6.783670E-12    0.000000E+00               7.55667E-04
        106  traj.phase.state_rate_defects:m    e   0.000000E+00    9.471588E-13    0.000000E+00               7.22205E-03
        107  traj.phase.state_rate_defects:m    e   0.000000E+00    5.043391E-13    0.000000E+00               1.46678E-02
        108  traj.phase.state_rate_defects:m    e   0.000000E+00    4.648805E-13    0.000000E+00               2.13684E-02
        109  traj.phase.state_rate_defects:m    e   0.000000E+00    7.062860E-13    0.000000E+00               2.76422E-02
        110  traj.phase.state_rate_defects:m    e   0.000000E+00   -6.810108E-13    0.000000E+00               3.32279E-02
        111  traj.phase.state_rate_defects:m    e   0.000000E+00   -3.421707E-13    0.000000E+00               3.92442E-02
        112  traj.phase.state_rate_defects:m    e   0.000000E+00   -1.522671E-13    0.000000E+00               4.58714E-02
        113  traj.phase.state_rate_defects:m    e   0.000000E+00   -8.643086E-14    0.000000E+00               5.25118E-02
        114  traj.phase.state_rate_defects:m    e   0.000000E+00   -6.045164E-14    0.000000E+00               5.93900E-02
        115  traj.phase.state_rate_defects:m    e   0.000000E+00   -4.451994E-14    0.000000E+00               6.62004E-02
        116  traj.phase.state_rate_defects:m    e   0.000000E+00   -3.702594E-14    0.000000E+00               7.27824E-02
        117  traj.phase.state_rate_defects:m    e   0.000000E+00   -3.153033E-14    0.000000E+00               7.83185E-02
        118  traj.phase.state_rate_defects:m    e   0.000000E+00   -2.980949E-14    0.000000E+00               8.20305E-02
        119  traj.phase.state_rate_defects:m    e   0.000000E+00   -2.886580E-14    0.000000E+00               8.23073E-02
        120  traj.phase.state_rate_defects:m    e   0.000000E+00   -3.153033E-14    0.000000E+00               7.79689E-02
        121  traj.phase.state_rate_defects:m    e   0.000000E+00   -3.630429E-14    0.000000E+00               6.71584E-02
        122  traj.phase.state_rate_defects:m    e   0.000000E+00   -5.095924E-14    0.000000E+00               5.01809E-02
        123  traj.phase.state_rate_defects:m    e   0.000000E+00   -9.697798E-14    0.000000E+00               2.60528E-02
        124  traj.phase.state_rate_defects:m    e   0.000000E+00   -1.067257E-12    0.000000E+00               2.78617E-03


   Exit Status
      Inform  Description
           0  Solve Succeeded
--------------------------------------------------------------------------------
Problem: problem
Driver:  pyOptSparseDriver
  success     : True
  iterations  : 18
  runtime     : 8.3029E-01 s
  model_evals : 18
  model_time  : 1.4295E-02 s
  deriv_evals : 17
  deriv_time  : 9.1189E-02 s
  exit_status : SUCCESS
from IPython.display import HTML

# Define the path to the HTML file
html_file_path = p.get_reports_dir() / 'traj_results_report.html'
html_content = html_file_path.read_text()

# Inject CSS to control the output cell height and avoid scrollbars
html_with_custom_height = f"""
<div style="height: 800px; overflow: auto;">
    {html_content}
</div>
"""

HTML(html_with_custom_height)
trajectory results for traj

Notes on the solution#

We can see that the collocation solution accurately captures the jump in the thrust. The oscillatory behavior observed is a result of interpolation performed post solution rather than a property of the solution itself.

References#

[Med64]

J. Meditch. On the problem of optimal thrust programming for a lunar soft landing. IEEE Transactions on Automatic Control, 9(4):477–484, 1964. doi:10.1109/TAC.1964.1105758.