- #1
GreenPrint
- 1,196
- 0
Homework Statement
One interesting property of a Fibonacci sequence is that the ratio of the values of adjacent members of the sequence approach a number called “the golden ratio” or PHI. Create a program that accepts the first two numbers of a Fibonacci sequence as a user input and then calculates additional values in the sequence until the ratio of adjacent values converges to within 0.001. You can do this in a WHILE loop by comparing the ratio of element k to element k-1 and the ratio of element k-1 to element k-2. If you call your sequence x, then the code for the WHILE statement is
while abs(x(k)/x(k-1) – x(k-1)/x(k-2))>0.001
Homework Equations
The Attempt at a Solution
I thought this would work fine but sense MATLAB can only compute with so many digits I'm at a lost as to what to do
Code:
a=input('Please enter the first two numbers of the Fibonacci sequence in "[# #]" form.');
x=[a ones(realmax-2)];
k=[3:1:realmax-1];
while abs(x(k)/x(k-1)-x(k-1)/x(k-2))>.001
x(k)=x(k-2).*x(k-1);
end
c(find(c>1));
maybe the issue is that I don't know enough about the golden ratio and the math behind it and stuff or is it that I don't know enough about MATLAB probably a combination of the two lol