Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The C version is below: #include float expdev(long *idum) /*Returns an exponentially distributed, positive, random deviate of unit mean, using ran1(idum) as the source of

The C version is below:
#include
float expdev(long *idum)
/*Returns an exponentially distributed, positive, random deviate of unit mean, using
ran1(idum) as the source of uniform deviates.*/
{
float ran1(long *idum);
float dum;
do
dum=ran1(idum);
while (dum == 0.0);
return -log(dum);
}
The FORTRAN version is here :
FUNCTION expdev(idum)
!USES ran1
!Returns an exponentially distributed, positive, random deviate of unit mean, using
!ran1(idum) as the source of uniform deviates.
INTEGER idum
REAL expdev
REAL dum,ran1
1 dum=ran1(idum)
if(dum.eq.0.) goto 1 ! so that random number is set to differ than 0 !
expdev=-log(dum)
return
END
Please use these codes and also ran1.f90 and ran1.c (which we compiled and executed in the class) functions, and generate 10 random number for the seed matrix below :
int nuvem[11]={-9,1,2,9,16,25,36,49,64,3,-11}; //for C
integer d(10)
DATA d/1,2,9,16,25,36,49,64,3,-11 ! For FORTRAN
image text in transcribed
image text in transcribed
image text in transcribed
\#include math. h> float ranl(long *idum) /*"Minimal" random number generator of Park and Miller with Bays-Durham shuffle and added safeguards. Returns a uniform random deviate between 0.0 and 1.0 (exclusive of the endpoint values). Call with idum a negative integer to initialize; thereafter, do not alter idum between successive deviates in a sequence. RNMX should approximate the largest floating value that is less than 1.\% \{ \#define IA 16807 \#define IM 2147483647 \#define AM (1.0/IM) \#define IQ 127773 \#define IR 2836 \#define NTAB 32 \#define NDIV (1+( IM-1)/NTAB) \#define EPS 1.2e-7 \#define RNMX (1.0-EPS) int j; long k; static long iy =0; static long iv[NTAB]; float temp; //printf("in idum=\%ld",*idum); if (*idum =0;j) \{ k=( *idum)/IQ; //Load the shuffle table (after 8 warm-ups). *idum =IA(idumkIQ)-IR k; if ( idum RNMX) return RNMX; //Because users don't expect endpoint values. else return temp; \} FUNCTION ranl(idum) INTEGER :: idum,IA,IM,IQ,IR,NTAB,NDIV REAL :: ranl,AM,EPS,RNMX PARAMETER (IA=16807,IM=2147483647,AM=1./IM,IQ=127773,IR=2836,& NTAB=32,NDIV=1+(IM1)/NTAB,EPS=1.2e7,RNMX=1,EPS) !"Minimal" random number generator of Park and Miller with Bays-Durham shuffle and !added safeguards. Returns a uniform random deviate between 0.0 and 1.0 (exclusive of !the endpoint values). Call with idum a negative integer to initialize; thereafter, do not !alter idum between successive deviates in a sequence. RNMX should approximate the largest !floating value that is less than 1 . INTEGER : j,k,iv(NTAB),iy SAVE iv,iy DATA iv / NTAB0/, iy /0/ if (idum.le.0.or.iy.eq. 0 ) then idum =max(1 *idum, 1) do j=NTAB+8,1,1 k=idum/LQ idum =IA (idum- kIQ ) IRk if (idum.It.0) idum=idum + IM if (j.le.NTAB) iv(j)=idum end do iy=iv(1) end if k=idum/1Q idum =IA (idum- kIQ )-IR*k if (idum.lt. 0 ) idum=idum +IM j=1+iy/NDIV iy=iv(j) iv(j)=idum ran1=min(AMi,RNMX) return END FUNCTION ranl

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 27th International Conference Dasfaa 2022 Virtual Event April 11 14 2022 Proceedings Part 2 Lncs 13246

Authors: Arnab Bhattacharya ,Janice Lee Mong Li ,Divyakant Agrawal ,P. Krishna Reddy ,Mukesh Mohania ,Anirban Mondal ,Vikram Goyal ,Rage Uday Kiran

1st Edition

3031001257, 978-3031001253

More Books

Students also viewed these Databases questions