Optimal control for nonlinear systems with quadratic performance