An efficient gradient technique for the solution of optimal control problems