%
%  Second example for fopt
%
%  set the initial parameters
%
  s0 = [1;0;1;0]; 
  k = 1.5;
  told = 1e-4;
  tols = 3e-3;
  mxit = 50;
  eta = 0.5;
%
%  Guess the final time
%
  tf = 3.3155;
%
%  Guess the initial control sequence
%
  beta = [0.5:0.25:5.5];
  N = length(beta)-1;
  t = tf*[0:1/N:1];
%
%  determine the initial guess for theta
%
   tu = [t' beta'];%
%  run the code
%
  [tu,ts,tf,nu,la0] = fopt('bobs_fopt_a',tu,tf,s0,k,told,tols,mxit,eta);
  fprintf(1,'Final time is  %f \n', tf);
%
%  Now plot the results
%
   utime = tu(:,1);
   beta = tu(:,2);
%
  stime = ts(:,1); r = ts(:,2); u = ts(:,3); v = ts(:,4); theta = ts(:,5);
% 
  x = r.*cos(theta);
  y = r.*sin(theta);
%  
  figure;
  orient tall
  plot(x,y); grid; xlabel('x/r_e'); ylabel('y/r_e');
      