It is common that chemical processes are modeled dynamically using differential-algebraic equations (DAEs) or ordinary differential equations (ODEs). Optimization of these dynamic problems is a hard work, and there are few general codes to do this kind of work. In this paper, we presented a method, which based on polynomial approximate on finite element, rSQP(reduced sequential quadratic programming)algorithm and automatic differentiation, to solve this kind of problems. This method firstly fully discretized the model by approximating state and control profiles by a kind of polynomials on finite elements. Then rSQP are used to solve the discretized model, the structure and the sparsity of discretized model are fully utilized. Because it hard to obtain first order gradient information of discretized model, we adopted a hybrid automatic differentiation technique to acquire the gradient information accurately and quickly. Computational results of three benchmark examples of dynamic optimization demonstrate that the proposed algorithm is quite effective.