  This paper concerns the numerical procedure for solving hybrid optimal
control problems with sliding modes. The proposed procedure has several
features which distinguishes it from the other procedures for the problem.
First of all a sliding mode is coped with differential-algebraic equations
(DAEs) and that guarantees accurate tracking of the sliding motion surface. The
second important feature is the calculation of cost and constraints functions
gradients with the help of adjoint equations. The adjoint equations presented
in the paper take into account sliding motion and exhibit jump conditions at
transition instants. The procedure uses the discretization of system equations
by Radau IIA Runge--Kutta scheme and the evaluation of optimization functions
gradients with the help of the adjoint equations stated for discretized system
equations. In the first part of the paper we demonstrate the correspondence
between the discrete adjoint equations and the discretized version of the
continuous adjoint equations in the case of system equations described by ODEs.
We show that the discrete adjoint state trajectories converge to their
continuous counterparts in the case of ODEs.
