%F_11_9 plots Lyapunov exponent versus rho parameter of the logistic equation
clear
d=500;
p_iter=1000;
%r=[-5 5];
r=[3.2 4];
v=2000;
ys=[-2 1];
xi=0.09;
oureps=2e-5;
f='rho.*x.*(1-x)';
x=xi;
rho=linspace(r(1,1),r(1,2),v);
delta=oureps;
  for iter=1:p_iter
     xnew=eval(f);
     x=x+delta;
     xpnew=eval(f);
     delta=oureps*sign(xpnew-xnew);
     x=xnew;
  end
sumratio=zeros(1,v);
for iter=(p_iter+1):(p_iter+d)
       xnew=eval(f);
       x=x+delta;
       xpnew=eval(f);
       findzero=find(xpnew-xnew==zeros(size(xpnew-xnew)));
       xnew(findzero)=[];
       xpnew(findzero)=[];
       rho(findzero)=[];
       sumratio(findzero)=[];
       delta=oureps*sign(xpnew-xnew);
       sumratio=sumratio+log(abs((xpnew-xnew)./oureps));
       x=xnew;
   end
le=sumratio./d;
plot(rho,le)
xlabel('\rho','Fontsize',12)
ylabel('Lyapunov exponent','Fontsize',12)
title('Plot of the Lyapunov exponent versus \rho for the logistic equation','Fontsize',12)
grid