%
%  Second example for dop0
%
%  set the initial parameters
%
  s0 = [0;0;0;0];
  tf = 1; 
  k = -0.5;
  told = 1e-7;
  tols = 1e-7;
  mxit = 50;
  eta = 0.2;
%
%  set the number of samples
%
  N = 100;
%
%  determine the initial guess for theta
%
   th = pi/3*linspace(1,0,N);
   t = linspace(0,tf,N);
   tu = [t' th'];
%
%  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);
%   th = interp1(old_t,old_th,t');
%   tu = [t' th]
%   figure; plot(old_t,old_th,'+',t,th,'o'); legend('old','new');
%   title([ 'N = ' num2str(N)]); grid;  
%
%  run the code
%
  [tu,ts,nu,la0] = fopc('bobs_fopc_a',tu,tf,s0,k,told,tols,mxit,eta);
  fprintf(1,'Final cost is  %f \n', ts(end,2))
%
%  save the most recent results
%
  old_th = tu(:,2);
  old_t = tu(:,1);
  save old_ut old_th old_t

%
%  Now plot the results
%
   utime = tu(:,1);
   th = tu(:,2);
 %
  stime = ts(:,1); u = ts(:,2); v = ts(:,3); y = ts(:,4); x = ts(:,5);
  figure;
  orient tall
  subplot(3,1,1); plot(x,y); grid; xlabel('x/gt_f^2'); ylabel('y/gt_f^2');
  subplot(3,1,2); plot(utime,th*180/pi); grid; ylabel('\theta (deg)'); 
  subplot(3,1,3); plot(stime,u,'-',stime,v,'--'); legend('u','v',2);grid;
  xlabel('t/f_f (sec)');
%
      