The finite-difference method in optimal control problems