Regularization and the computation of optimal trajectories