%%% MAKES A COB WEB PLOT FOR A LOGISTIC MAP

%%%% STEP 1: PLOT THE MAP FUNCTION AND THE LINE y=x
 fplot('2.8*y*(1-y)',[0 1]); hold on;
 axis('square'); axis([0 1 0 1]);

 fplot('1*y',[0 1],'r');

 
%%%%%% STEP 2: COMPUTE TRAJECTORY 
a=2.8;          
x0=0.2          % Initial condition 
N=40;           % Number of iterations
x(1) = x0;    
for ic=1:N
 x(ic+1) = a*x(ic)*(1-x(ic)); 
end

%%%%%% STEP 3: PLOT COBWEB
 line([x(1) x(1)],[0 x(2)],'Color','r') 
  plot(x(1), x(1),'ko');
 for ic=1:N-1
  line([x(ic) x(ic+1)],[x(ic+1) x(ic+1)],'Color','r')  
  line([x(ic+1) x(ic+1)],[x(ic+1) x(ic+2)],'Color','r')
  plot(x(ic+1), x(ic+1),'ko');
 end
 line([x(N) x(N+1)],[x(N+1) x(N+1)],'Color','r') 
 
   %%%%%% STEP 4: SIGN THE PLOT
   ht=text(0.1,0.82,['a=3.3']); set(ht,'FontSize',12);
   figure
   plot(x)
