%
%   SF_DEMO1.M  Plot slope field and several solution curves associated
 %                      with function f(x,y) = sin(x-y)
%
%   This slope field example (SF_DEMO1) comes from Sec 1.3 of Edwards and Penny 
%   (Prentice Hall, 2004).  In particular, it uses Matlab to reproduce the slope  
%   field and solution curves in Fig. 1.3.25.
%
%   Calls SF_DEMO_EQN.M to evaluate desired function
%         SFIELD.M to plot slope field
%
%   Note: There is another file, SF_DEMO2.M, that just creates the slope field
%   for this problem (no call to ODE23 to produce the solution curves).  For HW #5, 
%   which focuses on simply generating the slope fields, you should start with 
%   SF_DEMO2 (not the current file), since I want you to generate the approximate  
%   solution curves by hand...
%
%   File prepared by J. R. White, UMass-Lowell (Feb. 2007)
%
      
%
%   getting started
      clear all;   close all;   nfig = 0;
%
%   use SFIELD to plot slope field
      v = [-5 5 -5 5];                      % set range [minx maxx miny maxy]
      sfield('sf_demo_eqn',v,26); axis(v);  % plot slope field over range of interest
      title('SF\_Demo1:  Slope Field and Solution Curves for y'' = sin(x-y)')
      xlabel('x values'),ylabel('y values')
%
%   NOTE:  In Chapter 2, we will talk about numerical solution schemes and one of 
%          Matlab's built-in ODE solvers is ODE23.  For demonstration, in the next
%          section of code, I use ODE23 to actually generate several solution curves 
%          for a variety of different initial conditions.  We will talk a lot more 
%          about the details here at a later date...
%
%   find the solution curve for several different initial conditions (use ODE23)
      hold on
      xo = -5;   xf = 5;   yo = [-12 -6.8 -3.5 -1.2  0  4];   Ni = length(yo);
      for n = 1:Ni
        [x,y] = ode23('sf_demo_eqn',[xo xf],yo(n));
        plot(x,y,'r-','LineWidth',2)
      end
      hold off
%
%   end of demo