% define parameter between 0 and 4
r=2.8;

% define initial condition between 0 and 1
x(1)=0.6;

% define how many iteration steps you want to do
nmax=30;

% do iterations. at the end you will have sequence x(n)
for(n=1:nmax-1)
	x(n+1)=r*x(n)*(1-x(n));
end

%plot time course
figure(1)
plot([1:nmax],x,'o-')
xlabel('n')
ylabel('x_n')

%plot cobwebbing
figure(2)
xtemp=[0:.01:1];
%plot f(x)
plot(xtemp,r.*xtemp.*(1-xtemp),'b');
xlabel('x_n')
ylabel('x_{n+1}')
hold on
% plot diagonal
plot(xtemp,xtemp,'g')
%plot cobweb
plot([x(1) x(1)],[0 x(2)],'k')
for (n=2:nmax-2)
plot([x(n) x(n+1)],[x(n+1) x(n+1)],'k')
plot([x(n+1) x(n+1)],[x(n+1) x(n+2)],'k')
end

