Sunday, April 6, 2014

MATLAB code for #Fibonacci #EasterBunny marshmallow peep sequence


I made a Fibonacci marshmallow Easter bunny peep sequence:














For non-nerds who don't get the joke, a brief explanation from the UK on Fibonacci Numbers and the Golden Section :


The Fibonacci numbers are

The golden section numbers are
0·61803 39887... = phi = φ and
1·61803 39887... = Phi = Φ

Admittedly, until relatively recently, I wouldn't have gotten the joke, either. I was aware that the Fibonacci sequence existed as a mathematical curiosity, but was unaware that it was developed to explain how rabbits breed. I just happened to learn this fact by watching a documentary on Julia Robinson, the first female president of the American Mathematical Society, and contributor to the solution of Hilbert's 10th Problem:






From a downloadable link to the transcript of the above documentary "Julia Robinson and Hilbert's Tenth Problem"
ANNA SALAMON (1998 Julia Robinson Prize Winner)

There’s a sequence of numbers called the Fibonacci numbers and the way you get them is the first and second Fibonacci numbers are one. And after that you get the next one by adding the two before it. So one and one is two, one and two is three, two and three is five, three and five is eight, and you just keep going forever. The Fibonacci numbers were invented by Leonardo of Pisa, who was called Fibonacci because he was the son of Bonacci, in the year 1220 to solve a problem involving the reproduction of rabbits.


STEVE GIVANT

Let me read to you a translation of the original statement of Fibonacci’s problem from the  Liber Abacci. “A man put one pair of rabbits in a certain place, entirely surrounded by a wall. How many pairs of rabbits can be produced from that pair in a year if the nature of rabbits is such that every month each pair bears a new pair which from the second month on become productive?”

An illustration of how Fibonacci Numbers describe bunny breeding is included on Tom Wolverson's 2/1/14 blog post "Perfect Proportion? The Golden Ratio?" (warning! his post begins w/a big photo of a woman's derriere, so it's PG13):















Julia Robinson worked w/a Soviet mathematician, Yuri Matijasevich, to help solve Hilbert's 10th (H10) problem. Yuri used Fibonacci numbers to help solve H10 from pdf download "My Collaboration with Julia Robinson" by Yuri Matijasevich:








In particular, the sequence

0,1,3,8,21 . . . . (14)
of Fibonacci numbers with even indices satisfies the recurrence relation

{b.+l = 3(I). - 6 . - 1 (15)

similar to (7). This sequence grows like [(3 + V5)/2]" and can be used instead of (11) for constructing a relation of exponential growth.

Matlab provided a link to a free Matlab code to create a Fibonacci sequence

Since the linked site requires log in, I copied and pasted the text


fibonacci series

by


02 Jan 2014 (Updated )

a code in order to display the fibonacci series in and to find the nth term


fibnoacci.m


%fibonacci series in Matlab
clc
clear all
a=input('the term upto which one wants to have fibonacci series:   ');
k=1;
b=0;
for i=0:a-1
    j=b+k;
    disp(j)
    t=k;
    k=j;
    b=t;
    f{i+1}=j;
end
g=input('enter the fibonaccis nth term:');
f{g}

However, the problem with the above code is that it doesn't calculate the first two terms of the Fibonacci sequence.


I merged Atluri  Krishna Sagar's code from above with


MatLab Fibonacci Sequence Script :

%Clear screen and memory

clear; clc;

n = input('n (number of Fibonacci terms to compute): ');

f(1) = 1;

f(2) = 1;

for i = 3:n

str = sprintf('%d term Fibonacci Sequence', i);

disp(str);

f(i) = f(i-1) + f(i-2)

end

Below are some screen shots and a brief refresher on how to run Matlab scripts:










 
0) Find a copy of Matlab or find someone who has a copy. If you're on a university website, then most colleges have site licenses. Simply do a program search and click to open copy.






1) make certain "Current Folder" in "Command" window linked to saved folder
2) hit new script doc icon to open up "Editor" window



3) copy and paste green text code above into script "Editor" window
4) w/ drag down "File" menu command, save file w/name like "fibonacci" or "fibnum" into "Current Folder"





5) type name of script (w/o .m file extension)  into Matlab "Command" window and hit "Enter" button to run script
 





When you run the above script, an Example Input :

n (number of Fibonacci terms to compute): 8


And an Example Output :

3 term Fibonacci Sequence
f =
1 1 2
4 term Fibonacci Sequence
f =
1 1 2 3
5 term Fibonacci Sequence
f =
1 1 2 3 5
6 term Fibonacci Sequence
f =
1 1 2 3 5 8
7 term Fibonacci Sequence
f =
1 1 2 3 5 8 13
8 term Fibonacci Sequence
f=
1 1 2 3 5 8 13 21
Thus, illustrating Yuri's Eqn (14) in paper above that the even terms (i.e. every other term) of the Fibonacci sequence are indeed 0,1,3,8,21 . . . .
A " Fibonacci Numbers in Matlab" post  gives the Matlab code for calculating the aforementioned Golden Ration Φ ~ 1.61803.....
  
The simple code is here:

%Clear screen and memory
clear; clc; format compact
% Initialize the first two values
f(1) = 1;
f(2) = 1;
% Create the first 30 Fibonacci numbers
for i = 3 : 30
% Perform the sum of terms accordingly

f(i) = f(i-1) + f(i-2);
% Calculate and display the ratio of 2 consecutive elements % of the series

golden_ratio = f(i)/f(i-1);
str = [num2str(f(i)) ' 'num2str(f(i-1)) ' ' ...
num2str(golden_ratio, 10)];
disp(str)

end

Each line shows three elements: a number in the series, its predecessor and the quotient of the first number divided by the second. The results in Matlab are here:

2 1 2
3 2 1.5
5 3 1.666666667
8 5 1.6
13 8 1.625
21 13 1.615384615
34 21 1.619047619
55 34 1.617647059
89 55 1.618181818
144 89 1.617977528
233 144 1.618055556
377 233 1.618025751
610 377 1.618037135
987 610 1.618032787
1597 987 1.618034448
2584 1597 1.618033813
4181 2584 1.618034056
6765 4181 1.618033963
10946 6765 1.618033999
17711 10946 1.618033985
28657 17711 1.61803399
46368 28657 1.618033988
75025 46368 1.618033989
121393 75025 1.618033989
196418 121393 1.618033989
317811 196418 1.618033989
514229 317811 1.618033989
832040 514229 1.618033989

You can see that, in fact, the quotient of two consecutive numbers reaches the 'golden ratio' after just a few numbers in the series.

Hence, to conclude, a Golden Ratio of little bunny Φ Φs ( phi phis instead of the more traditional little bunny foo foos) where Φ=1.6...and 1= 1 Golden Bunny; Decimal Point=Sugar Egg; 6=6 little foil bunnies.















===========

Update

------------------


Fibonacci sequences obviously don't just apply to bunnies, but to bees, as well, as link in my tweet with misspelled hashtag indicates:





And tho the puzzle above deals with honey bees, I'd still like to link to my favorite rendition of the "Flight of the Bumble Bee"


realizing that they belong to two different species




No comments :

Post a Comment