F = inline('y*exp(r*(1-y))');
hold on;
fprintf('\n*** Calculating the bifurcation diagram: this may take a few minutes...\n');
y0 = 0.5;

for r=2:0.01:3.5
  yn = y0;
  for n=1:110
    yn=F(r,yn);
  end
  for n=1:150;
    yn=F(r,yn);
    if ( abs(r-2.2) < 1e-3 || abs(r-2.6) < 1e-3 || abs(r-3.4) < 1e-3 )
        plot(r, yn, 'dr');
    else plot(r, yn);
    end
  end
end

set(gca,'fontsize',16);
title('Bifurcation diagram for Ricker equation y_{n+1}=y_n e^{r (1 - y_n)}');
xlabel('r'); ylabel('y_\infty');
axis tight;

