%
clf;
clear all
%
%  Function and parameter definitions
%
%r=3.1;
r=3.5;
r=4.0;
f=@(x) r*x.*(1-x);
x(1)=0.1;
N=50;
%
%  Cobweb diagram for N-iterates of f(x)
%
figure(1)
z=0:0.01:1;
plot(z,f(z),'b-',z,z,'r-')
hold on
for i=1:N
    x(i+1)= f(x(i));
    plot([x(i),x(i)],[x(i),x(i+1)],'g-');
    hold on
    plot([x(i),x(i+1)],[x(i+1),x(i+1)],'g-');
    hold on
end
title(['cobweb for r=',num2str(r)])
hold off
%
%  Orbit x_n versus n for N-iterates of f(x)
%
figure(2)
plot(1:length(x),x,'k-*')
title('x_n versus n')
%
