% Cobwebbing Script for the Logistic Equation
% Created by Ben Godkin 7/19/2022


n = 100;

rho = 3.5;

x = linspace(0,1,100);

f = @(u_n) rho*u_n.*(1-u_n);

u = zeros(n,1);
u_0 = 0.8;
u(1) = u_0;

for i=1:(length(u)-1)

    u(i+1) = f(u(i));

end


figure(1)
clf
hold on
plot(x,f(x),'k')
plot(x,x,'r')
plot(u_0, u_0, 'ro')
for i=1:(length(u)-1)

    line([u(i), u(i)], [u(i), u(i+1)],'color','b')
    drawnow
    pause(0.04)

    line([u(i), u(i+1)], [u(i+1), u(i+1)],'color','g')
    drawnow

    pause(0.04)    

end
hold off