MATLAB: I’m trying to plot the golden ratio to show that it converges

fibonaccigolden ratio

I'm trying to write a matlab script that displays the fibonacci sequence and plots the ratio of succesive members of the series (the golden ratio), 1/1=1; 2/1=2; 3/2=1.5 etc. I already figured out the code to display the fibonacci sequence. I just don't know how to plot the ratio. Here is my code I have so far.
%code
f=[1 1];
x=1;
while f(x) < 10000
f(x+2)=f(x+1)+f(x);
x=x+1;
end
f

Best Answer

Just add a line to calculate the ratio at each step. E.g.,
Initialize prior to the loop:
f_ratio = [1 1];
Then add inside the loop:
f_ratio(x+2) = f(x+2)/f(x+1);
Then after the loop:
plot(f_ratio);
Related Question