Fibonocci Numbers
Fibonocci numbers is given by
where
So the first few numbers are
What I done in this program is that entering a how many Fibonocci numbers you want, then I allocate the memeory for that array. Next is the simplest part, I iterate the Fibonocci number using (1), and write the result out.
Code
Result
Below screenshot shows the first 40 Fibonocci number.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Lastly, I plot the Fibonocci number vs. N. It clearly shows a extremly rapid growth.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
In 64 bit Fortran integer type, there are limit to the maximun digit you can hold in one variable. In order to calculate 200th Fibonocci number, I need to seperate this very long integer( 42 digits) into different place. What I do is assigning each digit to an element of array, so that I can store as big number as I desire. Hardest part is then to calculate the sum of two number which I store digit ny digit in two big array. Below program(line 30 to 36) show how I manage to calulate
the sum of two number by using two array.
Big Fibonocci Number
PROGRAM big_fibonacci
IMPLICIT NONE
INTEGER :: N, i, j, res=0
! store 50 digit of number of 3 Fibonocci numbers
INTEGER, DIMENSION(:, :), ALLOCATABLE :: fib
write(*, *) "Numbers of Fibonocci number you want >>>"
read(*, *) N
! allocate N x 50 array
allocate(fib(N, 50))
! initialize
fib = 0.
! F1 = F2 = 1
fib(1, 50) = 1
fib(2, 50) = 1
CALL big_addition
CONTAINS
SUBROUTINE big_addition
write(*, '(a)') repeat('=', 100)
write(6, '(50I2, 7I7)') fib(1, :), 1
write(6, '(50I2, 7I7)') fib(2, :), 2
do i = 3, N
res = 0
do j = 50, 1, -1
fib(i, j) = mod(fib(i-1, j) + &
fib(i-2, j) + res, 10)
res = (fib(i-1, j) + fib(i-2, j) + res &
- mod(fib(i-1, j) + fib(i-2, j) &
+ res, 10)) / 10
end do
write(6, '(50I2, 7I7)') fib(i, :), i
end do
write(*, '(a)') repeat('=', 100)
! write to a file
open(1, file='f200.dat', status='unknown')
do i = 1, N
write(1, '(50I1)') fib(i, :)
end do
END SUBROUTINE big_addition
END PROGRAM big_fibonacci
Result
Below screenshot show the 190th to 200th Fibonocci number which I store each digit seperatly(there is no way I can calculate this big number just using intrinsic Fortran function).
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Golden Mean
Golden mean is the ratio between two succescive Fibonocci numbers.
Code
Result
I can calculate two successive Fibonocci ratio and it converges to golden ratio very fast.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
If I calculate the error between the ratio I calculate and (3), the error decrease as N increase. I plot the N vs in which y axis is log scale. For , at least I need to calcuate the ratio between 31th and 30th Fibonocci number.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →