Computer Modelling Using FORTRAN
Computer Modelling Using FORTRAN
I.
Introduction
rom the time humankind started to ponder about questions that belong in the
scientific realm of philosophy, especially
Physics, the mathematics involved has always
been a challenge. As science advanced, the
language it was spoken in, namely Maths, got
more and more difficult to handle. Historically,
"scientific powerhouses", such as Harvard University or MIT, had to employ human calculators so that the burden of tiresome calculations
could be avoided by those who were on the
forefront of scientific innovation. But as technology caught on with the advancement of
science, especially with invention of the computer, much of this burden of crunching data
was awarded to computers. They were more
efficient in time, more accurate than humans
and most importantly, never got tired or bored.
II.
1 http://home.cern/about/computing
I.
II.
Bifurcation Diagrams
For a = 1 to 4
Do-Loops
As mentioned above, iterations are achieved using do-loops in FORTRAN and since we have
to reiterate the whole process over three variables, we use three do-loops, each with its own
purpose. On a very general basis, the three
do-loops have the following function:
The first do-loop increments from x1 to
xn , therefore finds the terms in the sequence for a particular value of x0 and
a.
! Listing
do i = 0 ,
next =
prev =
end do
the sequence
99
a * prev *(1 - prev )
next
For a = 3 to 4
III.
Fixed Points
IV.
Self-Similarity
It is very curious to see that the upper bifurcation is a smaller scale map of the original one. This is called Scale invariance or
Self-Similarity, wherein a pattern repeats itself
but on a smaller scale. The structure formed
thereby is called Fractals. These patterns are observed in probability distributions of random
3
III.
I.
Integral
Monte Carlo
Actual
0.786497
0.785398
Error
Expected
Actual
0.071
0.001099
IV.
A plot showing random points and the sin2 ( x )
Volume
Error
Monte Carlo
Actual
3.0696
3.03844
Expected
Actual
0.57735
0.03116
III.
Conclusions
References
[1] Drazin P. G., Nonlinear Systems, (1992)
[2] Guckenheimer John, Holmes Philips, Nonlinear Oscillations, Dynamical Systems, and
Bifurcations of Vector Fields, Applied Mathematical Sciences; vol.42 (1983)
[3] West J. Bruce, An Essay on the Importance of
Being Nonlinear in Journal of Mathematical
Biology; vol.62 (1985)
V.
I.
Appendices
A Pseudo-random number is not a random number in the truest sense, since given the initial
conditions, namely the seed, it can be completely determined. But it appears to be random since
we do not have any information about the initial conditions. So it appears to be random but is
actually not. John Von Neumann once joked that "Anyone who considers arithmetical methods of
producing random digits is, of course, in a state of sin." 4
4 more on "Various techniques used in connection with random digits" by John von Neumann(1951) https:
//dornsifecms.usc.edu/assets/sites/520/docs/VonNeumann-ams12p36-38.pdf
II.
II.1
Logistic Map
II.2
II.3
10
II.4
subroutine init_random_seed ()
use iso_fortran_env , only : int64
implicit none
integer , allocatable :: seed (:)
integer :: i , n , un , istat , dt (8) , pid
integer ( int64 ) :: t
call random_seed ( size = n )
allocate ( seed ( n ))
! First try if the OS provides a random number generator
open ( newunit = un , file = " / dev / urandom " , access = " stream " , &
form = " unformatted " , action = " read " , status = " old " , iostat = istat )
if ( istat == 0) then
read ( un ) seed
close ( un )
else
! Fallback to XOR : ing the current time and pid . The PID is
! useful in case one launches multiple instances of the same
! program in parallel .
call system_clock ( t )
if ( t == 0) then
call date_and_time ( values = dt )
t = ( dt (1) - 1970) * 365 _int64 * 24 * 60 * 60 * 1000 &
+ dt (2) * 31 _int64 * 24 * 60 * 60 * 1000 &
+ dt (3) * 24 _int64 * 60 * 60 * 1000 &
+ dt (5) * 60 * 60 * 1000 &
+ dt (6) * 60 * 1000 + dt (7) * 1000 &
+ dt (8)
end if
pid = getpid ()
t = ieor (t , int ( pid , kind ( t )))
do i = 1 , n
seed ( i ) = lcg ( t )
end do
end if
call random_seed ( put = seed )
contains
! This simple PRNG might not be good enough for real work , but is
! sufficient for seeding a better PRNG .
function lcg ( s )
integer :: lcg
integer ( int64 ) :: s
if ( s == 0) then
s = 104729
else
s = mod (s , 4294967296 _int64 )
11
end if
s = mod ( s * 279470273 _int64 , 4294967291 _int64 )
lcg = int ( mod (s , int ( huge (0) , int64 )) , kind (0))
end function lcg
end subroutine init_random_seed
5
5 The
12