# Fibonacci vs. Kilometers

This experiment was based on this Reddit posting: http://www.reddit.com/r/fifthworldproblems/comments/s0217/i_can_only_speak_in_a_recurring_meter_the/c4a4c18

Here’s a brief excerpt that sums up the point of this experiment:

Cool fact:

The Fibonacci sequence fairly accurately converts miles to kilometers. For each number in the sequence that represents miles, the next number is the same distance in kilometers

Wanting to test this, I threw together a quick Perl script to plot this out. The results were, surprisingly, “fairly accurate.”

I’ve included here a few quick plots, the numbers, and the raw source code should anyone wish to tinker further with this. Granted these are unrefined results from a presentation stand-point, but you get the point…    The raw results:

Miles, Calculated from Fibonacci, True
1,1,1.609
1,2,1.609
2,3,3.218
3,5,4.827
5,8,8.045
8,13,12.872
13,21,20.917
21,34,33.789
34,55,54.706
55,89,88.495

Miles, Percent Difference
1,-37.8495960223741
1,24.3008079552517
2,-6.77439403356122
3,3.58400662937643
5,-0.559353635798632
8,0.994406463642015
13,0.396806425395604
21,0.624463582822808
34,0.537418199100641
55,0.570653709249105
89,0.557956997507005
144,0.562806436019613
233,0.560954075386042
377,0.561661608360142
610,0.561391353961833
987,0.561494581832304
1597,0.561455152276278
2584,0.561470213023878
4181,0.561464460329799
6765,0.561466657663354
10946,0.561465818356607
17711,0.561466138943263
28657,0.561466016490064
46368,0.561466063263029
75025,0.561466045397334
121393,0.561466052221422
196418,0.561466049614862
317811,0.561466050610479
514229,0.56146605023018
832040,0.561466050375433

The source code:

` Perl |   copy code |?001002#!/usr/bin/perl003 004use GD::Graph::lines;005 006##################007# Computed values008 009\$last = 1;010\$cur = 1;011my @a;012 013print "Miles, Calculated from Fibonacci, True\n";014 015for (\$i = 0; \$i < 10; \$i++) {016        \$a[\$i] = \$last; #miles017        \$a[\$i] = \$cur;  # Fibonacci Calculated value018        \$a[\$i] = \$last * 1.609;  # computed value019        print \$a[\$i] . "," . \$a[\$i] . "," . \$a[\$i] . "\n";020 021        # increment the Fibonacci sequence022        \$x = \$cur; \$cur += \$last; \$last = \$x;023}024 025my \$mygraph = GD::Graph::lines->new(600, 400);026\$mygraph->set(027    x_label     => 'Miles',028    y_label     => 'Kilometers',029    title       => 'Miles to Kilometers',030) or warn \$mygraph->error;031 032my \$myimage = \$mygraph->plot(\@a) or die \$mygraph->error;033open OUTPUT, ">Fib_vs_KM.png";034print OUTPUT \$myimage->png;035close(OUTPUT);036 037#################038# % Error 1 - 55039 040print "\nMiles, Percent Difference\n";041 042\$last = 1;043\$cur = 1;044my @a;045 046for (\$i = 0; \$i < 10; \$i++) {047    \$a[\$i] = \$last; #miles048    \$a[\$i] = (\$cur - (\$last * 1.609)) / (\$last * 1.609) * 100;  # percent difference049 050        print \$a[\$i] . "," . \$a[\$i] . "\n";051    # increment the Fibonacci sequence052    \$x = \$cur; \$cur += \$last; \$last = \$x;053}054 055my \$mygraph = GD::Graph::lines->new(600, 400);056\$mygraph->set(057    x_label     => 'Miles',058    y_label     => '% Difference',059    title       => 'Percent Difference from Real (1 - 55 miles)',060) or warn \$mygraph->error;061 062my \$myimage = \$mygraph->plot(\@a) or die \$mygraph->error;063open OUTPUT, ">Fib_vs_KM_diff1.png";064print OUTPUT \$myimage->png;065close(OUTPUT);066 067############068# 89 - 6765069 070for (\$i = 0; \$i < 10; \$i++) {071    \$a[\$i] = \$last; #miles072    \$a[\$i] = (\$cur - (\$last * 1.609)) / (\$last * 1.609) * 100;  # percent difference073        print \$a[\$i] . "," . \$a[\$i] . "\n";074 075    # increment the Fibonacci sequence076    \$x = \$cur; \$cur += \$last; \$last = \$x;077}078 079my \$mygraph = GD::Graph::lines->new(600, 400);080\$mygraph->set(081    x_label     => 'Miles',082    y_label     => '% Difference',083    title       => 'Percent Difference from Real (89 - 6765 miles)',084) or warn \$mygraph->error;085 086my \$myimage = \$mygraph->plot(\@a) or die \$mygraph->error;087open OUTPUT, ">Fib_vs_KM_diff2.png";088print OUTPUT \$myimage->png;089close(OUTPUT);090 091 092#################093# 10946 - 832040094 095for (\$i = 0; \$i < 10; \$i++) {096    \$a[\$i] = \$last; #miles097    \$a[\$i] = (\$cur - (\$last * 1.609)) / (\$last * 1.609) * 100;  # percent difference098        print \$a[\$i] . "," . \$a[\$i] . "\n";099 100    # increment the Fibonacci sequence101    \$x = \$cur; \$cur += \$last; \$last = \$x;102}103 104my \$mygraph = GD::Graph::lines->new(600, 400);105\$mygraph->set(106    x_label     => 'Miles',107    y_label     => '% Difference',108    title       => 'Percent Difference from Real (10946 - 832040 miles)',109) or warn \$mygraph->error;110 111my \$myimage = \$mygraph->plot(\@a) or die \$mygraph->error;112open OUTPUT, ">Fib_vs_KM_diff3.png";113print OUTPUT \$myimage->png;114close(OUTPUT);115`

This entry was posted in Uncategorized. Bookmark the permalink.

This site uses Akismet to reduce spam. Learn how your comment data is processed.