Control Theory and Optimization I: Homogeneous Spaces and the Riccati Equation in the Calculus of Variations