# How do I display the first 20 numbers of the Fibonacci sequence?

16 Ansichten (letzte 30 Tage)
Seth Broberg am 27 Sep. 2020
Kommentiert: Sindar am 28 Sep. 2020
Need a for loop that displays the first 20 numbers of the Fibonacci sequence.
Here is my code so far
a=1
i=3
for a=1:20
f(i)=f(i-1)+f(i-2);
a+1
i+1
end
disp(f)
it currently displays as the output.
function_handle with value:
@(x,y)x.^2+y.^2
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Sindar am 28 Sep. 2020
you need to define the first two numbers manually, then start on the third
f(1) = 0;
f(2) = 1;
for a=3:20
...
Also, it's unclear what you are doing with 'i'
##### 2 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Sindar am 28 Sep. 2020
• what value is i taking here?
• do you understand what for a=3:20 does?
(also, you might want to check out the Matlab Onramp)

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on Loops and Conditional Statements 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!

Translated by