%QDMAP_CO draws a cobweb of the logistic equation.

% last modified  by S. H. Zak on December 5, 2002

clc
clear
disp('Specify the rho parameter, e.g., 0.7 or 1.4 or 2.8 or 3.6 or 3.9.')
rho=input('The rho parameter = ')
disp('Specify the number of iterations, e.g., 100 or 500.')
n_iter=input('The number of iterations n_iter = ')
ft='rho*t.*(1-t)';
axis([0 1 0 1]);
axis square
hold on
set(gca,'Fontsize',12)
xlabel('{\it x}({\it{k}})','Fontsize',12)
ylabel('{\it x}({\it{k}}+1)','Fontsize',12)
title('Cobweb of the logistic equation with {\it x}(0)=0.1','Fontsize',12)
t=linspace(0,1,1000);
plot(t,eval(ft))
plot(t,t)
fx='rho*x*(1-x)';
x_0=.1;
x=x_0;
y=eval(fx);
txy=linspace(0,y,2);
xx=x*ones(1,2);
plot(xx,txy);
%n_iter=1000;
for i=1:n_iter
f2(i)=eval(fx);
tl1=linspace(x,f2(i),2);
yy=f2(i)*ones(1,2);
plot(tl1,yy);
x=f2(i);
yn=eval(fx);
tl2=linspace(x,yn,2);
xxn=x*ones(1,2);
plot(xxn,tl2)
end
