% % cob.m % % cobweb plot of the logistic z = rz(1-z) iterates % % usage cob(r,N,p) % % N = number of points % p = length of pause between lines % % example cob(3.8,15,1) % function cob(r,N,p) z = zeros(1,N); z(1) = rand; x(1) = z(1); y(1) = 0; t = 0:.01:1; y = r*t.*(1-t); subplot(2,1,1) plot(t,y,'r') hold on plot(t,t,'g') for j=2:N, z(j) = r*z(j-1)*(1-z(j-1)); x(j) = x(j-1); y(j) = z(j); line([x(j-1) x(j)],[y(j-1) y(j)]) line([x(j) y(j)],[y(j) y(j)]) x(j) = y(j); pause(p) end hold off title(['Logistic Cobweb, r = ' num2str(r)],'fontsize',16) subplot(2,1,2) plot(z,'ko-')