Image from Pixabay The Fibonacci sequence was first observed by the Italian mathematician Leonardo Fibonacci in 1202. He was investigating how fast rabbits could breed under ideal circumstances. He made the following assumptions:
Fibonacci asked how many pairs of rabbits would be produced in one year. Can you create the numbers yourself? Remember to count the 'pairs' of rabbits and not the individual ones. Try it. Were you able to come up with the Fibonacci numbers? If not, here is how you would do it.
The pattern comes out to be 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233. Fibonacci numbers are of interest to biologists and physicists because they are frequently observed in various natural objects and phenomena. For example, the branching patterns in trees and leaves are based on Fibonacci numbers. On many plants, the number of petals is a Fibonacci number: buttercups have 5 petals; lilies and iris have 3 petals; some delphiniums have 8; corn marigolds have 13 petals; some asters have 21 whereas daisies can be found with 34, 55 or even 89 petals. How can we create a rule (algorithm) for the fibonacci series (sequence)? First, the terms are numbered from 0 onwards like this: n = 0 1 2 3 4 5 6 7 8 9 10 ... xn =0 1 1 2 3 5 8 13 21 34 55 ... What rule can we create here? Well, if you look, x3 = x2 + x 1 (2 = 1 + 1) and x4 = x2 + x3 (3 = 1 + 2), etc. So we can write the rule (algorithm) as: xn = x(n1) + x(n2). where:
Example: term 7 is calculated as: x7= x(71) + x(72) = x6 + x5 = 13 + 8 = 21 Let's write programs in Python to calculate the Fibonacci numbers. 1. With looping: def fib(n): a,b = 1,1 for i in range(n1): a,b = b,a+b return a print(fib(1)) print(fib(2)) print(fib(3)) print(fib(4)) print(fib(5)) print(fib(6)) print(fib(7)) print(fib(8)) 1. With recursion: def fibR(n): if n==1 or n==2: return 1 return fibR(n1)+fibR(n2) print(fibR(1)) print(fibR(2)) print(fibR(3)) print(fibR(4)) print(fibR(5)) print(fibR(6)) print(fibR(7)) print(fibR(8)) N.B: No not copy and paste the python code as identation is important.
0 Comments
Leave a Reply. 
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
September 2018
Categories
All
