Fibonacci Sequence and Caluclating a phi value
Show older comments
I am having trouble with this program running properly. It generates the fibonacci sequence no problem but when i need to calulate the phi value it does nothing. or at least diplays nothing. any ideas why it is not displaying any value for phi or displaying the number of iterations required?
here is my code:
clear;clc;
num1=input('Enter an integer,greater than three, for the number of terms in the sequence: ');
if (num1<=3 || rem(num1,1)~=0)
num1=input('Enter an integer greater than three');
end
num2=input('Enter a integer from 2 to 15 for the precision: ');
if (num2<2 || rem(num2,1)~=0)
num2=input('Please enter a valid integer between 2 and 15');
end
Npts=num1; m=1; d0=0; d1=1;
while(m<=Npts)
db(m)=d0;
d2=d1+d0;
d0=d1;
d1=d2;
m=m+1;
end
disp(db);
iter=0;
Npt=1000; f=1; b0=0; b1=1;
while(f<=Npt)
bd(f)=b0;
b2=b1+b0;
b0=b1;
b1=b2;
f=f+1;
end
phi= abs((bd(2)/bd(1))-((bd(3)/bd(2))));
if(phi< (10^-num2))
disp(iter);
disp(phi);
else
t=4;
bd(1)=bd(2);
bd(2)=bd(3);
bd(3)=bd(t);
t=t+1;
end
iter=iter+1;
any input would be appreciated! Thanks in advance.
Accepted Answer
More Answers (0)
Categories
Find more on Pole and Zero Locations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!