For loop fibonacci sequence
Mostrar comentarios más antiguos
I need to create a Fibonacci sequence using the for loop function. the first two number of the Fibonacci sequence must be defined from a user input.
I then need to plot this on a polar graph with the element number as the angle and value of the element in the sequence for the radius
3 comentarios
Steven Lord
el 1 de Mayo de 2018
This sounds like a homework assignment. If it is, show what you've written to try to solve the problem and ask a question about the specific issue that's blocking you from moving forward and we may be able to offer some guidance.
dominic blackler
el 1 de Mayo de 2018
Editada: James Tursa
el 1 de Mayo de 2018
Muhammed Roshdy
el 17 de Abr. de 2019
Editada: Muhammed Roshdy
el 17 de Abr. de 2019
% Fibonacci sequence
clear;clc;
sequence_end=25; %Insert the Sequence end here
F_curr=zeros(1,sequence_end);
golden_ratio=zeros(1,sequence_end-1);
F_curr(1) = 0; %Insert First Value of the sequence here
F_curr(2) = 1; %Insert second Value of the sequence here
i=3;
golden_ratio(1)=F_curr(2)/F_curr(1);
for n=3:sequence_end
F_curr(i)=F_curr(i-1)+ F_curr(i-2);
golden_ratio(i-1)=F_curr(i)./F_curr(i-1);
i=i+1;
end
disp(F_curr)
disp(golden_ratio(end))
Respuesta aceptada
Más respuestas (2)
Tasbiha Azeemi
el 14 de Mayo de 2018
0 votos
Try this one!!!
function a=FabonacciSequence(n)
a(1)=0;
a(2)=1;
for i=1:n;
a(i+2)=a(i+1)+a(i)
end
end
1 comentario
Milan Parikh
el 19 de En. de 2021
It is not correct method
Nwajiobi Chibueze
el 16 de Feb. de 2020
Editada: Nwajiobi Chibueze
el 16 de Feb. de 2020
0 votos
x = input('enter the first and second number of the sequence:')
y = input('enter the number of elements in the sequence:')
for k = 3:y
n(1) = x;
n(2) = x;
n(k) = n(k-1)+n(k-2);
end
n
polar(n)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!