- #1

- 7

- 0

## Homework Statement

First of all, I used the Window xp & Compaq Visual Fortran 6.6 installed in VMware workstation.

In my case, there are no compile and link errors in source code, and excuting that program is also done.

But I want to generate 300 random numbers by using my program (Log-normally distributed).

In the case of j=1,2,3,...,117, there is no errors. but,

the case of j is larger than 117, the error is occured (no error messages in window console, but

no calculation.................The calculation step is not progressed...).

**The source code is attached below.........**

<Input Data>

3.93e-5,235421, 65889643, 15484354, 1235487, 4758, 85697, 2.9624, -14.5322

2. Homework Equations

<Input Data>

3.93e-5,235421, 65889643, 15484354, 1235487, 4758, 85697, 2.9624, -14.5322

2. Homework Equations

Algorithms 712: Generate a normally distributed pseudo-random number.

The algorithm uses the ratio of uniforms method of A.J. Kinderman and J.F. Monahan augmented with quadratic bonding curves.

## The Attempt at a Solution

In the first time, I see the message "image expended maximum...." So, I added the ignore terms in setting menu, (/ignore:4084).

Fortran:

```
Program Test
Implicit none
integer i, n0d, j
real xkbdot, m, lkbdot(310)
real seed1, seed2, a1, b11, c1, d1, sigma, mu
real X1, X2, S, T1, A, B, R1, R2, RANDN(310)
real u(310), v(310), q(310), kbdot(310)
real rand1(310), rand2(310), x(310), y(310)
open(unit=1, file="input", form="formatted", status="unknown")
read(1,*) xkbdot, SEED1, SEED2, A1, B11, C1, D1, sigma, mu
j=1
X1=MOD(A1*SEED1,B11)
X2=MOD(C1*SEED2,D1)
RAND1(j)=X1/B11
RAND2(j)=X2/D1
SEED1=X1
SEED2=X2
DO WHILE (j .le. 150)
X1=MOD(A1*SEED1,B11)
X2=MOD(C1*SEED2,D1)
RAND1(j)=X1/B11
RAND2(j)=X2/D1
SEED1=X1
SEED2=X2
C... Generate Log-normally Distributed Random Numbers..............C
S=0.449871
T1=-0.386595
A=0.19600
B=0.25472
R1=0.27597
R2=0.27846
C... Generate P=(u,v) uniform in rectangle enclosing acceptance region ..............C
50 u(j)=RAND1(j)
v(j)=RAND2(j)
v(j)=1.7156*(v(j)-0.5)
C... Evaluate the quadratic form ..............C
X(j)=u(j)-S
Y(j)=ABS(v(j))-T1
Q(j)=X(j)**2+Y(j)*(A*Y(j)-B*Y(j))
C... Accept P if inside inner ellipse ..............C
IF (Q(j) .LT. R1) GO TO 100
C... Reject P if outside outer ellipse ..............C
IF (Q(j) .GT. R2) GO TO 50
C... Reject P if outside acceptance region ..............C
IF (v(j)**2 .GT. -4.0*LOG(u(j))*u(j)**2) GO TO 50
C... Return ratio of P's coordinate as the normal deviate ..............C
100 RANDN(j)=v(j)/u(j)
C... Generate value of kbdot ..............C
LKBDOT(j)=RANDN(j)*sigma+mu
IF (LKBDOT(j) .gt. -2.30) then
KBDOT(j)=xkbdot
ELSE
KBDOT(j)=exp(LKBDOT(j))
END IF
write(*,*) j, KBDOT(j)
j=j+1
End do
End
```