In this article some of the results for optimal control of linear systems have been generalized to a nonlinear case. This is achieved by employing standard techniques of the nonlinear theory. After demonstrating the existence of optimal controls, finite element method is used to discretize the problem. The resulting finite dimensional problem is solved by a special algorithm. The theoretical discussions are completed by proving that approximate solutions are reduced to exact solutions as the element size tends to zero. This study is closed by a presentation and a discussion of several related numerical results.