% This is code to draw the direction field for 
% the system x'=-(x-y)(1-x-y); y'=x(2+y)

% first set the range by setting a,b,c,d
% the direction field will be drawn 
% for the region [a,b]*[c,d] in the phase plane
a=-0.5;
b=0.5;
c=-0.5;
d=0.5;

[x, y] = meshgrid(a:0.05:b, c:.05:d);
xdot = -(x-y).*(1-x-y); %Note the use of .* and .^
ydot = x.*(2+y);

r=sqrt(xdot.^2+ydot.^2);

FigHandle = figure;
set(FigHandle, 'Position', [100, 100, 1049, 895]);
set(0,'DefaultTextFontSize',30,'DefaultAxesFontSize', 30)

quiver(x,y,xdot, ydot)
title('Direction Field')


FigHandle = figure;
set(FigHandle, 'Position', [700, 500, 1249, 895]);
set(0,'DefaultTextFontSize',30,'DefaultAxesFontSize', 30)


quiver(x,y,xdot./r, ydot./r)
title('Normalized Direction Field')