Practical Optimal Control
A Step-by-Step Approach to Optimal Control Problems
The first step to solve any problem is writing it down. As this section's focus is optimal control problems, I will formalize the process by which I face any optimal control problem. The goal is to write down a set of necessary conditions that any locally optimal solution must satisfy so that whether we eventually solve the problem analytically or numerically, we may verify that it satisfies them. The first step is to write down the values of interest.
With the values now written down, we move to the functions that relate these quantities.
We are now ready to take the first step towards solving the optimal control problem. We write two Lagrangians, the end-point Lagrangian and the Lagrangian of the Hamiltonian. First, the Lagrangian of the Hamiltonian is written as, $$ \bar{H}(\boldsymbol{x}(t),\boldsymbol{u}(t),\boldsymbol{\lambda}(t),\boldsymbol{\mu}(t),t) = H(\boldsymbol{x}(t),\boldsymbol{u}(t),\boldsymbol{\lambda}(t),t) + \boldsymbol{\mu}^T(t) \boldsymbol{h}(\boldsymbol{x}(t),\boldsymbol{u}(t),t) $$ where the Hamiltonian is, $$ H(\boldsymbol{x}(t),\boldsymbol{u}(t),\boldsymbol{\lambda}(t),t) = F(\boldsymbol{x}(t),\boldsymbol{u}(t),t) + \boldsymbol{\lambda}^T(t) \boldsymbol{f}(\boldsymbol{x}(t),\boldsymbol{u}(t),t) $$ We have introduced the co-states, denoted $\lambda_j(t)$, $j=1,\ldots,n_x$, where each co-state is associated with the corresponding state variable $x_j(t)$. They evolve according to the following differential equations, $$ \dot{\lambda}_j(t) = -\frac{\partial \bar{H}}{\partial x_j} = -\frac{\partial F}{\partial x_j} - \left(\frac{\partial \boldsymbol{f}}{\partial x_j} \right)^T \boldsymbol{\lambda}(t) - \left( \frac{\partial \boldsymbol{h}}{\partial x_j} \right)^T \bm{\mu}(t) $$ Also introduced are the co-path values, denoted $\mu_j(t)$, $j = 1,\ldots,n_h$, associated with each path constraint. They follow the complementarity condition, $$ \mu_j(t) \left\{ \begin{array}{lll} \leq 0 & \text{if} & h_j(\boldsymbol{x}(t),\boldsymbol{u}(t),t) = h_j^L\\ = 0 & \text{if} & h_j^L < h_j(\boldsymbol{x}(t),\boldsymbol{u}(t),t) < h_j^U\\ \geq 0 & \text{if} & h_j(\boldsymbol{x}(t), \boldsymbol{u}(t),t) = h_j^U\\ \text{unrestricted} & \text{if} & h_j^L = h_j^U \end{array} \right. $$ Finally, the Lagrangian of the Hamiltonian provides the condition for a control to be optimal, called the stationarity condition, $$ \frac{\partial \bar{H}}{\partial u_j} = 0, \quad j = 1,\ldots,n_u $$
The end-point Lagrangian is written as, $$ \bar{E} = E(\boldsymbol{x}(t_0),\boldsymbol{x}(t_f),t_0,t_f) + \boldsymbol{\nu}^T \boldsymbol{e}(\boldsymbol{x}(t_0),\boldsymbol{x}(t_f),t_0,t_f) $$ The end-point Lagrangian provides the two transversality conditions. $$ \boldsymbol{\lambda}(t_0) = -\frac{\partial \bar{E}}{\partial \boldsymbol{x}(t_0)} \quad \text{and} \quad \boldsymbol{\lambda}(t_f) = \frac{\partial \bar{E}}{\partial \boldsymbol{x}(t_f)} $$ The end-point Lagrange multipliers, $\nu_j$, $j = 1\ldots,n_e$, satisfy a similar complementarity condition as $\mu_j(t)$ did. $$ \nu_j \left\{ \begin{array}{lll} \leq 0 & \text{if} & e_j(\boldsymbol{x}(t_0),\boldsymbol{x}(t_f),t_0,t_f) = e_j^L\\ = 0 & \text{if} & e_i^L < e_j(\boldsymbol{x}(t_0),\boldsymbol{x}(t_f),t_0,t_f) < e_j^U\\ \geq 0 & \text{if} & e_j(\boldsymbol{x}(t_0),\boldsymbol{x}(t_f),t_0,t_f) = e_j^U\\ \text{unrestricted} & \text{if} & e_j^L = e_j^U \end{array} \right. $$ Finally, we can write the end point Hamiltonian conditions, $$ H|_{t=t_0} = \frac{\partial \bar{E}}{\partial t_0} \quad \text{and} \quad H|_{t=t_f} = - \frac{\partial \bar{E}}{\partial t_f} $$ Writing down each of these equations provides the necessary conditions which any locally optimal solution of the original optimal control problem must satisfy.
After the required book-keeping in step 1, writing the problem in step 2, and then writing the Hamiltonian and the various necessary conditions in step 3, it is time to stop and think about what the optimal solution might look like. There is no strict list of steps to take at this point, only experience can guide the process, but a general framework that can be useful is the following.
For most real problems, the differential equations that describe the evolution of the states and the co-states, $\boldsymbol{x}(t)$ and $\boldsymbol{\lambda}(t)$ respectively, cannot be solved analytically. A special exception is when the states are linear time-invariant (LTI), that is, $$ \dot{\boldsymbol{x}}(t) = A \boldsymbol{x}(t) + B \boldsymbol{u}(t) $$ The section on Minimum Energy Control describes this type of problem in general terms.
Sometimes, it can be useful to draw a graph which describes the relations between states. The graph has $n_x+n_u$ nodes, where each node is assigned either a state or an input. Add directed edges from node $x_j$ to node $x_k$ if $x_j$ appears in $f_k$. Similarly, add directed edges from node $u_j$ to node $x_k$ if $u_j$ appears in $f_k$ as well. This exercise can inform whether some of the states (or costates) are solvable even if the whole system of equations cannot be solved.