hand out fortran 77
TRANSCRIPT
-
7/25/2019 Hand Out Fortran 77
1/3
=== STA 6106 Computer-Intensive Methods in Statistics
Some Sample FOTA! "" #ro$rams ====
The following FORTRAN 77 program calls a random number generating function to generate a
single random number between 0 and 1, using an entered seed value, and entered values of the
generator constants
PROGRAM RANDGENR
PRINT*, 'Enter seed value, and values of A and B:'
READ*, SEED, A, B
PRINT*, 'Random numer !s ', RANDOM"SEED, A, B#
END
$%N&TION RANDOM"(, &ONST, DI)IS#
MOD"&ONST*(,DI)IS#
RANDOM +DI)IS
END
Note that all FORTRAN command lines must begin at column 7 or after, and cannot e!tend past
column 7" The first # columns are reserved for line numbers
The following FORTRAN 77 program generates a list of 100 random numbers between 0 and 1,
using a $O loop
PROGRAM RANDGENR
PRINT*, 'Enter seed value, and values of A and B:'
READ*, SEED, A, B
-
MOD"A*SEED,B#
SEED
DO ./I0E " 10E1 -((#
MOD"A*SEED,B#
RANDOM +B
PRINT*, RANDOM
SEED
2 -
ENDDO
END
The following FORTRAN 77 program uses the %aw of %arge Numbers to appro!imate the
integral 1
0
&dxx , using &000 pseudorandom numbers between 0 and 1 Note that the values of
the generator constants are written into the program' the onl( input is the seed value
PROGRAM RANDGENR
PRINT*, 'Enter seed value: '
READ*, SEED
-
A -34(5
B 6-75748375
MOD"A*SEED,B#
SEED
S%M (
-
7/25/2019 Hand Out Fortran 77
2/3
DO ./I0E " 10E1 6(((#
MOD"A*SEED,B#
RANDOM +B
PRINT*, RANDOM
S%M S%M 2 "RANDOM*RANDOM#
SEED
2 -
ENDDO
S%M S%M+6(((
PRINT*, 'Inte9ral !s aro;!matel< '
PRINT*, S%M
END
The following FORTRAN 77 program uses the %aw of %arge Numbers to appro!imate the
integral ( ) ( )01&
11
0
&
&
=
dze
z
, using &000 generated pseudorandom numbers
PROGRAM STDNORM
REA0 PI PRINT*, 'Enter seed value: '
READ*, SEED
PI 81-7-=>63=7
-
A -34(5
B 6-75748375
MOD"A*SEED,B#
SEED
S%M (
DO ./I0E " 10E1 6(((#
MOD"A*SEED,B#
RANDOM +B
PRINT*, RANDOM
ARGMNT "-+RANDOM# ? -
S%M S%M 2 ""EP"?(1=*"ARGMNT**6###+S@RT"6*PI##+"RANDOM**6#
SEED
2 -
ENDDO
S%M S%M+6(((
PRINT*, 'Inte9ral !s aro;!matel< '
PRINT*, S%M
END
The following FORTRAN 77 program calculates the value of ( ) ( )))
PROGRAM STDNORM
REA0 PI
PRINT*, 'Enter seed value: '
READ*, SEED
PI 81-7-=>63=7
-
A -34(5
B 6-75748375
MOD"A*SEED,B#
-
7/25/2019 Hand Out Fortran 77
3/3
SEED
S%M (
DO ./I0E " 10E1 6(((#
MOD"A*SEED,B#
RANDOM +B
PRINT*, RANDOM
ARGMNT ?7 2 "4*RANDOM#
S%M S%M 2 "4*"EP"?(1=*"ARGMNT**6###+S@RT"6*PI##
SEED
2 -
ENDDO
S%M S%M+6(((
PRINT*, 'Inte9ral !s aro;!matel< '
PRINT*, S%M
END
The following FORTRAN 77 program estimates the value of , using the algorithm discussed in
class Note that the number of pairs of pseudorandom numbers needs to be *uite large to get a
value close to
PROGRAM ESTPI
PRINT*, 'Enter seed values, and samle s!e: '
READ*, SEED-, SEED6, N
A -34(5
B 6-75748375
-
&O%NT (
- MOD"A*SEED-,B#
6 MOD"A*SEED6,B#
SEED- -
SEED6 6
DO ./I0E " 10E1 N# - MOD"A*SEED-,B#
6 MOD"A*SEED6,B#
RANDOM- -+B
RANDOM6 6+B
PRINT*, RANDOM-, RANDOM6
SEED- -
SEED6 6
""6*RANDOM-?-#**6#2""6*RANDOM6?-#**6#
I$ " 10E1 -# &O%NT &O%NT 2 -
2 -
ENDDO
PIEST 7*&O%NT+N
PRINT*, 'Est!mated value of PI ', PIEST END