Borrar filtros
Borrar filtros

Trying produce input to using while loops to create fibonacci sequence but i have done using the while and it is error.

1 visualización (últimos 30 días)
n=input('Enter the number that should not exceed:');
fibonacci(1)=input('Enter the first number:');
fibonacci(2)=input('Enter the second number:');
f(1) = 1;
f(2) = 1;
for i = 3 : 30
% SUM
f(i) = f(i-1) + f(i-2);
golden_ratio = f(i)/f(i-1);
str = [num2str(f(i)) ' ' num2str(f(i-1)) ' ' ...
num2str(golden_ratio, 10)];
disp(str)
end

Respuestas (1)

Jan
Jan el 30 de Nov. de 2017
What about this:
lim = 10000;
f(1) = 1;
f(2) = 1;
for i = 3 : 30
f(i) = f(i-1) + f(i-2);
golden_ratio = f(i) / f(i-1);
fprintf('%d: %d %d %.16g\n', i, f(i), f(i-1), golden_ratio);
if f(i) > lim
break; % Stop the "for i" loop
end
end
Or maybe the limits concerns the value of golden_ratio?

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by