Our paper presents a new method to solve a class of fractional optimal control problems (FOCPs) based on the numerical polynomial approximation. In the proposed method, the fractional derivative in the dynamical system is considered in the Caputo sense. The approach used here is to approximate the state function by the Legendre orthonormal basis by using the Ritz method. Next, we apply a new constructed operational matrix to approximate fractional derivative of the basis. After transforming the problem into a system of algebraic equations, the problem is solved via the Newton's iterative method. Finally, the convergence of the new method is investigated and some examples are included to illustrate the effectiveness and applicability of the proposed methodology.