function cobweb(iterates, x0,xmin, xmax)
% Based on a script by Justin Migacz
% This script makes a cobweb for the function "theMap"
% iterates =  the number of iterates
% x0 = initial condition
% xmin, xmax = the plot range

dx = (xmax-xmin)/200;
x = xmin:dx:xmax;       % This is the plot domain              
plot(x,theMap(x),x,x);  % make the plot of the function
                        % and diagonal
a = x0;                 % <----This is the starting point of the orbit
b = x0;
plot(x,x,'r',x,theMap(x),'g')   % Plot the diagonal and the function red and green
grid
 
for I = 1:iterates
    xp = theMap(x0);
    b = [b, xp,xp];            % On each iteration, two points 
    a = [a, x0,xp];            % are made for drawing lines
    x0=xp;                     % a and b are the vectors of the
                               % corresponding x,y points along
                               % their rows
                               % a=[x0,x1,x2,x3...]
                               % b=[y0,y1,y2,y3...]
end 
line(a,b,'Color',[0 0 1]) 