%
%  Second example for dop0
%
%  set the initial parameters
%
  s0 = [0;0;0];
  tf = 1; 
  k = -2;
  tol = 5e-5;
  eta = 0.5;
  mxit = 100;
%
%  set the number of samples
%
  N =100;
%
%  determine the initial guess for u
%
   u = 0*linspace(0,1,N);
   t = linspace(0.0,tf,N);
   tu = [t' u'];
%
%  interpolate between old values as we refine
%  comment these lines out for your initial estimate
%  uncomment them as you refine
%
%   load old_ut
%   t = linspace(0,tf,N);
%   u = interp1(old_t,old_u,t');
%   tu = [t' u]
%   figure; plot(old_t,old_u,'+',t,u,'o'); legend('old','new');
%   title([ 'N = ' num2str(N)]); grid;  
%
%  run the code
%
  [u,s,nu,la0] = dopc('bobs_dopc_a',u,s0,tf,k,tol,mxit,eta);
  fprintf(1,'Final cost is  %f \n', s(2,end))
%
%  save the most recent results
%
  old_u = tu(:,2);
  old_t = tu(:,1);
  save old_ut old_u old_t  
%
%  Now plot the results
%
  dt = tf/length(u);
  time = [0:length(u)]*dt;
  figure;
  orient tall
  subplot(3,1,1); plot(time(1:end-1),u); grid; ylabel('u(t)');
  subplot(3,1,2); plot(time,s(1,:)); grid; ylabel('v(t)');
  subplot(3,1,3); plot(time,s(1,:)); grid; ylabel('x(t)'); xlabel('Time (sec)');
%
  figure;
  orient tall
  plot(s(2,:),s(3,:)); grid; xlabel('x/gt_f^2'); ylabel('y/gt_f^2');
%
      