Optimization and control of dynamic systems