%
%  First example for fop0
%
%  set the initial parameters
%
 clear
  s0 = [1;1];
  tf = 0.5;
  k = 2.5;
  told = 5e-5;
  tols = 5e-5;
  mxit = 500;
%
%  set the number of samples
%
  N =20;
%
%  determine the initial guess for u
%
   u = 0*linspace(1,0,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
%
  [tu,ts,la0] = fop0('bobs_fop0_a',tu,tf,s0,k,told,tols,mxit);
%
%  save the most recent results
%
  old_u = tu(:,2);
  old_t = tu(:,1);
  save old_ut old_u old_t
%
%  Now plot the results
%
 t = ts(:,1);
 x = ts(:,2);
 y = ts(:,3);
 ut = tu(:,1);
 u = tu(:,2);
 
  orient tall
  subplot(2,1,1); plot(ut,u); grid; ylabel('u(t)');
  subplot(2,1,2); plot(t,x,'-',t,y,'--'); legend('x(t)','y(t)'); grid; xlabel('Time (sec)');
%
      