Using MATLAB specify the minimum number of elements and plot
Using MATLAB specify the minimum number of elements and plot
Recall that famous Fibonacci sequence is composed of elements created by adding the two previous elements. One interesting property of a Fibonacci sequence is that the ratio of the values of adjacent members of the sequence approaches a number called \"the golden ratio\" or Phi (phi). Create a program, which determines the minimum number of elements in the Fibonacci sequence needed to bring error in estimating Phi below 0.001Solution
Fibonacci series code.
%code
f=[1 1];
x=1;
while f(x) < 1000
f(x+2)=f(x+1)+f(x);
f_ratio(x+2)= f(x+2)/f(x+1);
D_ratio(x+2)=f_ratio(x+2)-f_ratio(x+1);
if D_ratio<=0.001
break
else x=x+1;
end
end
f %%fibanocci series
plot(f_ratio,\'b\');
hold on;
plot(D_ratio,\'r\')
grid On;
disp(\'element at which fibanocci ratio becomes 0.001 is\')
x
Command window result:
>> Fibanocci_golden_ratio_convergence
f =
Columns 1 through 7
1 1 2 3 5 8 13
Columns 8 through 14
21 34 55 89 144 233 377
Columns 15 through 18
610 987 1597 2584
element at which fibanocci ratio becomes 0.001 is
x =
17
>>
