Find value in Fibonacci sequence
Afficher commentaires plus anciens
Hi, i can't solve a problem. Considering the Fibonacci sequence:
function F = Fibonacci(n)
if n == 1
S(1,1) = 0;
elseif n == 2
S(1,1) = 0; S(2,1) = 1;
else
S(1,1) = 0; S(2,1) = 1;
for i = 3:n
S(i,1) = S(i-1,1) + S(i-2,1);
end
end
F = S(n,1);
end
I would like to create a function that accepts two inputs: a natural number m ∈ N and a number j that can take values 0 or 1.
If j = 0, the output is the largest number of the sequence lower than m;
If j = 1, the output is the lowest number of the sequence greater or equal to m.
I can't find a solution. Could someone help me?
Thank you
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!