% function y = nonlinshoot(a,b,n,alpha,beta,f,fy,fyp,tol,maxit)
%
% Non-linear shooting method to solve BVP
%
%   y'' = f(t,y,y') 
%   y(a) = alpha
%   y(b) = beta
%
%  using Newton's method and variational equation
% 
% Inputs
%  a,b    time interval
%
%  n      number of time subintervals
%
%  alpha  = y(a)
%
%  beta   = y(b)
%
%  f      function handle, for a general non-linear problem
%         example:
%
%         f = @(t,y,yp) -3*yp +2*y+2*t+3; 
%
%         the parameters are (in this order)
%         t   space variable
%         y   y(t)
%         yp  y'(t)
%
%  fy     function handle for derivative of f with respect to
%         y argument (SECOND argument)
%
%  fyp    function handle for derivative of f with respect to
%         yp argument (THIRD argument)
%
%  tol    tolerance for stopping iterations
%
%  maxit  maximum number of iterations
%
% Outputs
%  y      function y at the points t = a + i*(b-a)/n, i=0..n.

function y = nonlinshoot(a,b,n,alpha,beta,f,fy,fyp,tol,maxit)

% initial guess = slope of line satisfying b.c.
z = TO BE COMPLETED

for k=1:maxit,
 % setup first order system of ODEs containing DE + variational eq
 
 % extract y

 % output
 fprintf('it=%3d, z=%10.7f, phi=%12.4e\n',k,z,y(end)-beta);

 % check convergence
 if (abs(y(end)-beta)<tol) 
  return;
 end;

 % update z
 
end;
fprintf('max number of iterations (%d) reached and error is %g\n',maxit,abs(y(end)-beta));
