 function resid = orbit_r(z,DATA)
%  ORBIT is our subroutine for evaluating the nonlinear
%   functions to be zeroed. These correspond to
%
%     u(T_f) = 0               : zero radial velocity at the final time
%      v(T_f) = sqrt(mu/r(T_f)  : circular trasnverse velocity at T_f
%      tranversality condtion for lambda_r at T_f
%
% To evaluate these we solve an initial value problem forward in time
% for the combined state/adjoint system
%
%      x(1) : [r] radial - position
%      x(2) : [u] radial - velocity
%      x(3) : [v] transverse - velocity
%      x(4) : lambda-r
%      x(5) : lambda-u
%      x(6) : lambda-v
%
%   set initial conditions
%
      x0= [ 1.0 ;
            0.0 ;
            1.0 ;
           z(:) ];
%
   OPTIONS = odeset('RelTol',1.e-6,'AbsTol',1.e-6);
   [T,X] = ode45('rhs',[0 DATA.tf],x0,OPTIONS,DATA);
%
%  Evaluate the residuals
%
      x = X(end,:);
      resid = [ x(2) ;
              x(1)*x(3)*x(3)-1.0 ;
              x(3)*x(6)-2.0*x(1)*(x(4)+1.0)];
%
% return
%
              
