%
%   SFIELD.M   Plot slope field associated with function f(x,y)
%
%   This function file is modeled after the example in "Computing Projects" 
%   by Edwards and Penny (see pg. 10).
%
%   The inputs to the function are:
%      fn = string name of the file containing the function
%      rm = 4-element vector containing [minx maxx miny maxy]
%      Np = number of points in x and y direcions
%
%   File prepared by J. R. White, UMass-Lowell (Jan. 1998)
%

      function [dx,dy] = sfield(fn,rm,Np)
%
%   compute x,y grid
      xx = linspace(rm(1),rm(2),Np);  yy = linspace(rm(3),rm(4),Np);
      [x,y] = meshgrid(xx,yy);
%
%   evaluate function f(x,y) at each mesh point
      eval(['f = ',fn,'(x,y);'])
%
%   find the angle whose tangent is f(x,y) and determine the x and y components 
%   of the unit vector associated with this angle
      angle = atan(f);   dx = cos(angle);   dy = sin(angle);
%
%   eliminate complex components
      dx(find(imag(dx)~=0)) = NaN;
      dy(find(imag(dy)~=0)) = NaN;
%   
%   use QUIVER to plot the slope field for f(x,y)
      quiver(x,y,dx,dy);
%
%   end of function
%
