Optimal control of nonlinear systems with neural networks