What is the Fibonacci series? About History Algorithm and python Program
What is the Fibonacci Series?
As per the Google search, Fibonacci Series is a series of numbers
in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.
The Fibonacci Sequence is the series of numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …
The next number is found by adding up the two numbers before it.
- Here series starts with two numbers ie 0 and 1
- The 1 is found by adding the two numbers before it (0+1)
- The 2 is found by adding the two numbers before it (1+1),
- And the 3 is (1+2),
- and so on!
It is that simple!
Here is a longer list:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, …
Can you figure out the next few numbers?
History
The Fibonacci sequence appears in Indian mathematics in connection with Sanskrit prosody, as pointed out by Parmanand Singh in 1985.[8][10][11] In the Sanskrit poetic tradition, there was interest in enumerating all patterns of long (L) syllables of 2 units duration, juxtaposed with short (S) syllables of 1 unit duration. Counting the different patterns of successive L and S with a given total duration results in the Fibonacci numbers: the number of patterns of duration m units is Fm + 1.[9]
Knowledge of the Fibonacci sequence was expressed as early as Pingala (c. 450 BC–200 BC). Singh cites Pingala’s cryptic formula Misra cha (“the two are mixed”) and scholars who interpret it in context as saying that the number of patterns that forms beats (Fm+1) is obtained by adding one [S] to the Fm cases and one [L] to the Fm−1 cases. Bharata Muni also expresses knowledge of the sequence in the Natya Shastra (c. 100 BC–c. 350 AD). However, the clearest exposition of the sequence arises in the work of Virahanka (c. 700 AD), whose own work is lost but is available in a quotation by Gopala (c. 1135)
About Fibonacci The Man
His real name was Leonardo Pisano Bogollo, and he lived between 1170 and 1250 in Italy.
“Fibonacci” was his nickname, which roughly means “Son of Bonacci”.
As well as being famous for the Fibonacci Sequence, he helped spread Hindu-Arabic Numerals (like our present numbers 0,1,2,3,4,5,6,7,8,9) through Europe in place of Roman Numerals (I, II, III, IV, V, etc). That has saved us all a lot of trouble! Thank you, Leonardo.
Fibonacci Day
Fibonacci Day is November 23rd, as it has the digits “1, 1, 2, 3” which is part of the sequence. So next Nov 23 let everyone know!
The Rule for Fibonacci Series
The Fibonacci Sequence can be written as a “Rule”
First, the terms are numbered from 0 onwards like this:
n = | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | … |
xn = | 0 | 1 | 1 | 2 | 3 | 5 | 8 | 13 | 21 | 34 | 55 | 89 | 144 | 233 | 377 | … |
So term number 6 is called x6 (which equals 8).
Example: the 8th term is the 7th term plus the 6th term: x8 = x7 + x6 |
So we can write the rule:
The Rule is xn = xn-1 + xn-2
where:
- Here xn is term number “n”
- xn-1 is the previous term (n-1)
- And xn-2 is the term before that (n-2)
Python Program for Fibonacci Series
Algorithm as Here
1. Declare two variables representing two terms of the series. Initialize them to 0 and 1 as the first and second terms of the series respectively.
2. Initialize a variable representing loop counter to 0.
3. Loop from 0 to the total number of terms in the series.
4. In every iteration,
A. add the variables defined in step 1. This represents a term(or item) of the Fibonacci series.
B. assign the value of the second variable to the first and the sum in above step A to the second variable.
So Python program to generate the Fibonacci series written as per the above algorithm follows.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 | def fibonacci(num): num1 = 0 num2 = 1 series = 0 for i in range (num): print (series, end = ' ' ); num1 = num2; num2 = series; series = num1 + num2; # running function after taking user input num = int ( input ( 'Enter how many numbers needed in Fibonacci series- ' )) fibonacci(num) |
Thus the Output of the Execution is:
Enter how many numbers are needed in the Fibonacci series –
6
0,1,1,2,3,5,
Program using recursion
Create a recursive function that receives an integer as an argument. This integer argument represents the position in the Fibonacci series and returns the value at that position. Thus, if it receives 5, it returns the value at the 5th position in the Fibonacci series.
This recursive function returns 0 and 1 if the argument value is 0 or 1. For all other values, it calls itself with the sum of nth and (n-1)th positions.
The program reads the total number of elements in the Fibonacci series from the keyboard. It then initiates a loop starting from 0 till this input value. In every iteration, the recursive function is called and the resultant Fibonacci item for that position is printed.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 | def fibonacci(number): # return 0 and 1 for first and second terms if number = = 0 : return 0 elif number = = 1 : return 1 else : # return the sum of two numbers return fibonacci(number - 1 ) + fibonacci(number - 2 ) # read the total number of items in Fibonacci series max_item_input = input ( "Enter the number of items in Fibonacci series\n" ) max_item = int (max_item_input) # iterate from 0 till number of terms for count in range (max_item): print (fibonacci(count), end = "," ) |
Thus the output of the above execution is
1 2 3 | Enter the number of items in the Fibonacci series 8 0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , |
Applications of Fibonacci Series
- First of all the Fibonacci numbers are important in the computational run-time analysis of Euclid’s algorithm to determine the greatest common divisor of two integers: the worst case input for this algorithm is a pair of consecutive Fibonacci numbers.
- The Fibonacci numbers are also an example of a complete sequence. So, this means that every positive integer can be written as a sum of Fibonacci numbers, where anyone's number is used once at most.
- Fibonacci numbers are used by some pseudorandom number generators.
- They are also used in planning poker, which is a step in estimating software development projects that use the Scrum methodology.
- Also, Fibonacci numbers arise in the Fibonacci heap data structure analysis.
- Retracement of Fibonacci levels is widely used in technical analysis for financial market trading.
I hope this article will help you and if you have any questions/recommendations please comment below!
Comments
Post a Comment