function cobweb(fcn,x0,N,xmin,xmax,par)

%% This routine is taken from http://pages.pomona.edu/~aer04747/MatlabFiles.htm

% fcn is the name of the function, x0 is the starting
% value, N is the number of iterates, xmin and xmax
% give the range of x-values to be plotted, and 
% par is an optional parameter vector.

dx=(xmax-xmin)/1000;
x=xmin:dx:xmax;
if nargin > 5
    y=feval(fcn,x,par);
else
    y=feval(fcn,x);
end;
plot(x,y,'b',[xmin xmax],[0 0],'k',[0 0],[min(y)-.1*abs(min(y)) max(y)],'k',[xmin xmax],[xmin xmax],'g');
hold on
if nargin > 5
Y=iterates(fcn,x0,N,par);
else
    Y=iterates(fcn,x0,N);
end;
YY(1)=Y(1);
for i=1:N
    XX(2*i-1)=Y(i);
    XX(2*i)=Y(i);
    YY(2*i)=Y(i+1);
    YY(2*i+1)=Y(i+1);
end;
XX(2*N+1)=Y(N+1);

plot(XX,YY,'r',x0,0,'r*');
