function n = butterfly(y0, d, r)
% Function "butterfly(y0, d, r)" returns the iteration number at which the
% solutions of the Ricker's equation with parameter r and initial
% conditions y0 and y0+d deviate by 0.1 or more

f = inline('y*exp(r*(1-y))');
y = y0;
z = y0 + d;

for n=1:100
    y = f(r, y);
    z = f(r, z);
    % fprintf(' %2d | %15.9g | %15.9g | %.2e \n', n, y, z, abs(y-z) );
    if ( abs(y - z) > 0.1 ) return
    end
end;

fprintf('** The two solutions are within tolerance after 100 iterations\n');
