function []= SlopeField(xmin,xmax,ymin,ymax,f)
% the function f(x,y) must be entered as a string. For example if
%f(x,y)=y*cos(x), then you need to enter 'y.*cos(x)' for f

f = str2func(['@(x,y) ',f]); 
   % converts the string input into a function handle that
   % Matlab recognizes

stepsize1=abs(xmax-xmin)/40;
stepsize2=abs(ymax-ymin)/40;
[X,Y] = meshgrid(xmin:stepsize1:xmax, ymin:stepsize2:ymax);

dY=f(X,Y);
dX=ones(size(dY));
    %the vector [dX,dY]=[1,f(X,Y)] will have the correct slope,
    % and the "AutoScaleFactor" below will scale the slope
    % segments appropriately if we pick a nice relative factor
    % like e.g. 0.8
quiver(X,Y,dX,dY,'Color','k','LineWidth',1,'AutoScaleFactor',1,'ShowArrowHead','Off');
axis tight
end

