7

I've wanted to code something. I decided to take up simulating the Fibonacci sequence. Except: I can't understand what I thought is a simple process.

I want to start at the very beginning which from what I see is $(0,1)$.

Well.

$0 + 1 = 1$. I get the sum of the first two numbers $(0 , 1)$ and then the answer (sum again?).

$1 + 1 = 2$...

Isn't the Fibonacci sequence suppose to be $1 , 1 , 2 , 3,$ etc?

I can't get those first two results and I notice that a lot of members are using some very scary symbols like $F_{k + 2} = F_k + F_{k +1}$. I don't understand how to move forward and I'm embarrassed to ask this in real life.

Can someone explain this without the symbols?

Thomas Andrews
  • 177,126
3man75
  • 89
  • 2
  • starts 1, 1, then you add the previous two numbers for the next. 1+1 = 2, ... 1, 2; 1+2 = 3, .. 2,3, 2+3 = 5, ..... 3,5, 3+5 = 8, 1,1,2,3,5,8 etc... – Tobi Jan 03 '17 at 23:56
  • 2
    You can start at $0$ if you like. That's how the sequence starts in the Encyclopedia of Integer Sequences. Whether you start with $(0,1)$ or with $(1,1)$ the key is that any subsequent entry is the sum of it's two predecessors. – lulu Jan 03 '17 at 23:57
  • As for the "scary symbols" $F_{k+2}=F_k+F_{k+1}$, you can think of them as meaning something like F[k+2] = F[k] + F[k+1], where F is an array of numbers and k is an integer. –  Jan 04 '17 at 03:21

4 Answers4

4

Each member of the Fibonacci sequence is the sum of the previous two members. There are two standard ways of starting the sequence - you might start with $0$ and $1$, or with $1$ and $1$.

Starting with $0$ and $1$, we have $0 + 1 = 1$; so the third member of our sequence is also $1$ and our sequence so far is $0,1,1$. $1+1 = 2$, so we now have $0,1,1,2$. $1+2=3$, so we have $0,1,1,2,3$. $2+3=5$, so we have $0,1,1,2,3,5$; and so on.

If you start with $1$ and $1$, you're just starting one step later, so you get $1,1,2,3,5,\ldots$, which is the version you've seen. Whether the Fibonacci sequence is "supposed" to start with $0$ or with $1$ is really just a matter of taste.

1

Unfortunately there are two common definitions of the Fibonacci sequence: $1,1,2,3,\ldots$ and $0,1,1,2,3\ldots,$ which is different only by the initial zero. The second is a bit more common. Note that they both share the property that a term is the sum of the two previous terms.

1

It starts $1, 1$, - or $0$ and $1$, then you add the previous two numbers for the next. $$ 1+1 = 2 ... 1,2 \\ 1+2 = 3, .. 2,3 \\ 2+3 = 5, .. 3,5 \\ 3+5 = 8, $$

you'll start to get the series.

$1,1,2,3,5,8, \cdots$

To code the series of numbers, you can use an array say fib

fib.push(fib[fib.length-1]+fib[fib.length-2])

simple example of something in a loop.

Tobi
  • 842
0

The rule is this: to get the next number in the sequence, and the "second to last" and "last" numbers together. $$ 0+1=1\\ 1+1=2\\ 1+2=3\\ 2+3=5 $$ So far, our sequence is $0,1,1,2,3,5$. To get the next number, add the second to last number (3) to the last number (5). $3+5=8$, so the next number is $8$.

Ben Grossmann
  • 225,327