 The solution method involves defining an ancillary function known as the Hamiltonian
(t) \mathbf{f}(\mathbf{x}(t),\mathbf{u}(t),t)
which combines the objective function and the state equations much like a Lagrangian in a static optimization problem, only that the multipliers formula_16, referred to as "costate variables", are functions of time rather than constants.The goal is to find an optimal control policy function formula_17 and, with it, an optimal trajectory of the state variable formula_18, which by Pontryagin's maximum principle are the arguments that maximize the Hamiltonian,
The first-order necessary conditions for a maximum are given by

the latter of which are referred to as the costate equations.Together, the state and costate equations describe the Hamiltonian dynamical system (again analogous to but distinct from the Hamiltonian system in physics), the solution of which involves a two-point boundary value problem, given that there are formula_25 boundary conditions involving two different points in time, the initial time (the formula_1 differential equations for the state variables), and the terminal time (the formula_1 differential equations for the costate variables; unless a final function is specified, the boundary conditions are formula_28, or formula_29 for infinite time horizons).