In this article, Ritz approximation have been employed to obtain the numerical solutions of a class of the fractional optimal control problems based on the Caputo fractional derivative. Using polynomial basis functions, we obtain a system of nonlinear algebraic equations. This nonlinear system of equation is solved and the coefficients of basis polynomial are derived. The convergence of the numerical solution is investigated. Some numerical examples are presented which illustrate the theoretical results and the performance of the method.