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

% y'' = f(x,y,y')
f = @(x,y,yp) y^3 - y*yp;
% y'(a)=alpha and y(b)=beta
a = 1; alpha=-1/4;
b = 3; beta=1/4;
n=1000;
ymin=0; ymax=4;

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

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

 % space discretization
 x = a + (0:n)'*(b-a)/n;
 
 % plots soluion
 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 only
 [junk,z] = ginput(1);
end;

