  Solutions to optimal control problems can be discontinuous, even if all the
functionals defining the problem are smooth. This can cause difficulties when
numerically computing solutions to these problems. While conventional numerical
methods assume state and input trajectories are continuous and differentiable
or smooth, our method is able to capture discontinuities in the solution by
introducing time-mesh nodes as decision variables. This allows one to obtain a
higher accuracy solution for the same number of mesh nodes compared to a fixed
time-mesh approach. Furthermore, we propose to first solve a sequence of
suitably-defined least-squares problems to ensure that the error in the dynamic
equation is below a given tolerance. The cost functional is then minimized
subject to an inequality constraint on the dynamic equation residual. We
demonstrate our implementation on an optimal control problem that has a
chattering solution. Solving such a problem is difficult, since the solution
involves infinitely many switches of decreasing duration. This simulation shows
how the flexible mesh is able to capture discontinuities present in the
solution and achieve superlinear convergence as the number of mesh intervals is
increased.
