A Riccati-equation-based algorithm for nonlinear optimal control problems