14 April 2006

the Golden Ratio and the Fibonacci series (Perl program)

I've been re-reading Dan Brown's The Da Vinci Code lately, and I was intrigued by the Golden Ratio and how it relates to the Fibonacci series. The Fibonacci series is such that each term is the sum of the previous two terms:
1, 1, 2, 3, 5, 8, 13, ...

The ratio of consecutive terms in the Fibonacci series converges on the Golden Ratio, which has a value of approximately 1.618. It also shows up in a geometric analysis of the pentacle. These properties are discussed in mathematical detail on the following Web pages:

the Golden Ratio
pentacle geometry

I wanted to see this from a computational point of view, so I wrote a quick Perl program to compute the Fibonacci numbers and ratios out to around 100 terms. The program prints out deviations from the Golden Ratio, and the output shows a near-zero deviation after less than 40 terms.


#!/usr/bin/perl -w

use strict;
use diagnostics;

my $NUM_ITERATIONS = 100;
my $GOLDEN_RATIO = 0.5 * (1.0 + sqrt(5));

my ($previous_term, $current_term) = (1, 1);
my $iteration_number = 1;
while ( $iteration_number <= $NUM_ITERATIONS ) {
my $new_term = $previous_term + $current_term;
my $ratio = $new_term / $current_term;
my $deviation = abs($GOLDEN_RATIO-$ratio) / $GOLDEN_RATIO;
printf "% 3d: %e\n", $iteration_number, $deviation;
$previous_term = $current_term;
$current_term = $new_term;
$iteration_number++;
}

1 comment:

zach said...

If your a fan of the band Tool, they actually used the Fibonacci sequence for some lyrics in one of thier songs.The song is called "Lateralus" off of their 2001 albulm by the same name. Below is some of the lyrics and their sylables and how they correspond to the Fibonacci sequence. Note: The lyrics are as they are sung, I have not changed their order in order to make this work. Tool the band should get full credit. If your into music, I highly recommend you check them out. www.toolband.com

Lateralus Lyrics:
Check out the syllables...
Sequence 1:
1 = Black
1 = then
2 = white are
3 = all I see
5 = in my infancy.
8 = red and yellow then came to be,
5 = reaching out to me.
3 = lets me see.

Sequence 2:
13 = As below, so above and beyond, I imagine
8 = drawn beyond the lines of reason.
5 = Push the envelope.
3 = Watch it bend.

Sequence 3:
1 = Black
1 = then
2 = white are
3 = all I see
5 = in my infancy.
8 = red and yellow then came to be,
5 = reaching out to me.
3 = lets me see.
2 = there is
1 = so
1 = much
2 = more that
3 = beckons me
5 = to look through to these
8 = infinite possibilities.