The Fibonacci sequence is a model for rabbit population growth. It starts with t
ID: 2997550 • Letter: T
Question
The Fibonacci sequence is a model for rabbit population growth. It starts with two 1's then the next number is the sum of the prior two numbers nk=nk?1 +nk?2 . The first few
numbers are: 1 1 2 3 5 8 13 . As the sequence gets large the ratio of one number over the prior number approaches a constant called the Golden Ratio nk? ? . Write a function
to compute the Golden Ratio using the Fibonacci sequence. Compare each new value to the last value of the Golden Ratio then exit if the difference is less than 2*eps. Limit the total number of iterations to 200. Plot on the same graph both the approximation of the Golden Ratio and the Fibonacci number for each k on separate y axises.
Explanation / Answer
x1=1;
x2=1;
GRatio=x2/x1;
for i=1:200
t=x1+x2;
GRatioTemp=t/x2;
if((GRatio-GRatioTemp)<(2*eps))&&((GRatioTemp-GRatio)<(2*eps))
break
end
Table(i,1)=x2;
Table(i,2)=GRatio;
GRatio=GRatioTemp;
x1=x2;
x2=t;
end
GRatio
plot(Table(:,2))
plot(Table(:,1))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.