% Demo for Shooting Method for a linear BVP
%
% close the window to stop infinite loop
%
% Fernando Guevara Vasquez 2012

% y'' = f(x,y,y')
f = @(x,y,yp) -y;
% y'(a)=alpha and y(b)=beta
a = 0; alpha=sqrt(2)-1;
b = pi; beta=1;
n=1000;
ymin=-2; ymax=2;

% set up function for RK
F = @(t,y) [y(2)
	    f(t,y(1),y(2))];
z=1; % true z is -1
figure(1); clf;
while (1)
 % intial condition
 y0 = [z,alpha];

 % vectorized Runge-Kutta method
 yt = rk4(a,b,n,y0,F);

 % the space discretization
 x = a + (0:n)'*(b-a)/n;

 % plot solution
 plot(x,yt(1,:),b,beta,'r*');

 % keep axis fixed
 axis([a,b,ymin,ymax])

 % waits for the user to click and returns the ordinate
 [junk,z] = ginput(1);
end;

