%Fibonacci sequence clear all %number of months to simulate N=20; %make ``blank" list of pairs in seqential months f=zeros(1,N) ; %initial conditions f(1) = 1; f(2) = 2; %iterate for n=3:N f(n) = f(n-1) + f(n-2); end figure subplot(311) plot(1:N,f,'-','Linewidth',2) ; hold on ylabel('f','FontSize',18) xlabel('n','FontSize',18) subplot(312) plot(1:N,log(f),'-','Linewidth',2) ; hold on ylabel('log f','FontSize',18) xlabel('n','FontSize',18) %analyze ! %ratio of successive fibonnaci numbers ratios=zeros(1,(N-1)) ; for n=1:N-1 ratios(n) = f(n+1)/f(n) ; end subplot(313) plot(1:N-1,ratios,'-','Linewidth',2) ; hold on ylabel('ratios','FontSize',18) xlabel('f','FontSize',18) %find first month where number of rabbits exceeds 1500 for n=1:N if f(n) > 1500 break end end disp('first month where number of rabbits exceeds 1500 is') n save critical_fibonacci_month.dat n -ascii