The inverted pendulum has Lagrangian , and equation where is the angle to the vertical. Alternatively, let be the Cartesian coordinates of the position of the pendulum, subject to the constraint .
The Lagrangian is then
and the mechanical equations are
where we have set an horizontal force as the control .
We want to minimize the objective
Figure 1 shows the states , the control and multiplier .
Discretization: Runge Kutta 4 with 400 steps.
We take here , and .
The final conditions are
The initial conditions are