Tuesday, November 13, 2012

Fibonacci and Phi

In between working through calculus and data structures, I figured a quick post about an interesting sequence would be a good change of pace.

The Fibonacci series is a pretty interesting one, it simply looks like this: $1, 1, 3, 5, 8, 13, 21, 34, 55, 89, ...$etc. So, what makes the fibonacci sequence interesting? Well, lots of things, especially the golden ratio.

Before, I continue talking about it I want to quickly demonstrate how it can be generated using a simple python program. If you haven't noticed, the pattern for this sequence is $F_{n} = F_{n-1} + F_{n-2}$ or simply, to get the next number in the sequence, you add the previous two numbers. So, in python we get something like this (using a list to hold all the numbers):
 fib_list = [1, 1]

def fibonacci(count):
    for n in range(0, count):
        fib_list.append(fib_list[n] + fib_list[n+1])
        
fibonacci(40)        
print fib_list[-1]
This will print out $267914296$, or the $42^{nd}$ element in this series.

A quick explanation of this code: First, we create a list that has the first two numbers; Next, we set up a for loop to iterate through these numbers (until we have done so "count" times); Finally, for each iteration, we append to the end of the list the sum of the two numbers that came before it.

There are several different ways you can program this. I chose to do it this way because, Python is easy to read and it's currently the language I have been writing in. When I first learned this sequence, I programmed it recursively in C. Now, on to the interesting part.

If we take the ratio of $\frac{F_{n+1}}{F_{n}}$ where, $n = 2$ we get $\frac{5}{3}$, which equals $1.666...$. What about if we try where $n = 5$? $\frac{21}{13}$, which equals about $1.615$. Looks like we're approaching some number around $1.6$; this is where limits can be helpful. If we evaluate the limit $$\lim \limits_{n \to \infty}\frac{F_{n+1}}{F_{n}}$$ we'll see that (skipping some steps) it is approaching $1.6180339...$etc. This number is known as phi($\phi$) or the value of the golden ratio.

This number is pretty interesting because it can be found everywhere in design and nature. In nature we can see that many plants tend to grow in a structure that follows this ratio. A quick Google image search of something like "fibonacci in nature", will show you plenty of plant images (among others) that follow this ratio and, in turn, have fibonacci numbers for total spirals or points at their outer layer. For example, in this picture you can see that from the center a spiral kind of forms outward and there are 21 leaves; which of course is a fibonacci number. If you spend enough time looking, you will find this ratio everywhere from design and architecture to music and paintings.

Anyways, thought it was worth a little bit of explanation for such an interesting series/irrational number.  When you really look around, you find that it's all too common. I guess, the question to ask is, why?

Check out this youtube video for a more visual explanation.

Any questions, comments and/or suggestions are appreciated.