Dynamical Systems and Optimal Control