%Function cobweb
%Author: Marius Ionescu
%Close all the current pictures
close all; 
a=3.8;
N=30; %number of iterations
x=0:0.01:1;
y=f_logistic(x,a);
z=x;
%Draw multiple graphs in one window
hold on
% Draw the function and the line z=x
plot(x,y,x,z)
%Pick an initial point
x=0.01;
yo=0;
for i=1:N
    yn=f_logistic(x,a);
    %draw a line from (x0,0) to (x0,y0=f(x0)) using red color
    line([x x], [yo yn],'Color','r');
    pause(0.5)
    line([x yn], [yn yn],'Color','r');
    pause(0.5)
    x=yn;
    yo=yn;  
end
hold off % release the picture; next graphs will be drawn in a new figure