%
%   SF_DEMO5.M  Plot slope field for function f(x,y) = sqrt(y) 
%
%   This problem generates the slope field and solution curves for y' = sqrt(y).
%   Note that this gives non real-values for y < 0.  The point of this particular 
%   demo is to show how the SFIELD and ODE23 routines respond to this situation.
%
%   Calls SF_DEMO5_EQN.M to evaluate desired function
%         SFIELD.M to plot slope field
%
%   File prepared by J. R. White, UMass-Lowell (Feb. 2005)
%
      
%
%   getting started
      clear all;   close all;   nfig = 0;
%
%   use SFIELD to plot slope field
      v = [-1 5 -4 4];    % [minx maxx miny maxy]
      sfield('sf_demo5_eqn',v,25);  axis(v);
      title('SF\_Demo5: Slope Field and Solution Curves for y'' = sqrt(y)')
      xlabel('x values'),ylabel('y values')
      hold on
%
%   Note: The ODE23 routine allows complex solutions.  However, when trying to
%         visualize these, the PLOT command simply ignores the imaginary components.   
%         To account for this rather confusing situation, any complex solution points
%         are simply eliminated -- since we desire real solutions here anyway...
%
%   let's find the solution curve for several different initial conditions (use ODE23)
      xo = -1;   xf = 5;   yo = [-3 -1 0 1 3];   Ni = length(yo);
      for n = 1:Ni
        [x,y] = ode23('sf_demo5_eqn',[xo xf],yo(n));
        y(find(imag(y)~=0)) = NaN;     % eliminates complex solution points
        plot(x,y,'r-',xo,yo(n),'g*','LineWidth',2)
      end
      hold off
%
%   end of problem
