08-07-2014, 03:14 PM
This program uses the following algorithm to generate Exponentially distributed variables:
Memory Map and Flags
Listing
Usage
-----
1. Enter initial/new random number seed and press [f][E].
2. Enter value for theta and press [f][A].
3. Enter the number of iterations and press [C]. The program will stop and display the averages for two sample sets. If flag 0 is set, the program will stop after calculating each random number. You must then press [R/S] to resume. You can clear flag 0 and then press [R/S] to resume the program at full speed.
4. Press [R/S] to view the standard deviations for the same two sample sets. Then press [R/S] to view teh expcted mean. FInnaly, press [R/S] to view the exepcted standard deviation.
5. (optional) Press [E] to generate a uniform random number.
6. (optional) Press [A] to generate an exponential random number.
7. (optional) Press [f][C] to generate a sample of 20 Exponenaially distributed random numbers that are store in registers R0 to R9 and Rs0 through Rs9.
Code:
Given parameter theta
1. Generate u=U(0,1)
2. X = -1/Theta*ln(u)
Expected mean = 1/Theta
Expected sdev= 1/Theta
Memory Map and Flags
Code:
R A = Theta
R E = random number seed
R 0 = used
R I = loop counter
F 0 = When manually set, the program stops after calculating each exponenitally distributed number, after pressing [C]. When cleared, the program proceed in full speed after pressing [C] or after resuming the program by pressing [R/S].
Listing
Code:
1 LBL e # Store seed
2 STO E
3 RTN
4 LBL E # Calculate uniform random number
5 RCL E
6 PI
7 +
8 5
9 Y^X
10 FRC
11 STO E
12 RTN
13 LBL a # Store theta
14 STO A
15 RTN
16 LBL A # Calculate one Exponential random number
17 GSB E
18 LN
19 CHS
20 RCL A
21 /
22 RTN
23 LBL C # Test mean and sdev for Exponential numbers
24 STI # Store number of iterations
25 P<>S
26 0
27 STO 4
28 STO 5
29 STO 6
30 STO 7
31 STO 8
32 STO 9
33 P<>S # Clear stat registers
34 LBL 0
35 GSB A
36 STO 0
37 F? 0
38 R/S
39 GSB A
40 F? 0
41 R/S
42 RCL 0
43 Sigma+
44 DSZ
45 GTO 0
46 x-bar # view the averages
47 R/S
48 s # view the standard deviations
49 R/S
50 RCL A
51 1/X
52 R/S # view expected mean
53 R/S # view expected sdev
54 RTN
55 LBL c # Store a sample of 20 Exponentially distributed random numbers
56 1
57 9
58 STI # Store number of iterations
59 LBL 1 # loop to generate and store the fr=irst 19 numbers
60 GSB A
61 STO (i)
62 DSZ
63 GTO 1
64 GSB A # Generate and store the 20th random number
65 STO 0
66 RTN
Usage
-----
1. Enter initial/new random number seed and press [f][E].
2. Enter value for theta and press [f][A].
3. Enter the number of iterations and press [C]. The program will stop and display the averages for two sample sets. If flag 0 is set, the program will stop after calculating each random number. You must then press [R/S] to resume. You can clear flag 0 and then press [R/S] to resume the program at full speed.
4. Press [R/S] to view the standard deviations for the same two sample sets. Then press [R/S] to view teh expcted mean. FInnaly, press [R/S] to view the exepcted standard deviation.
5. (optional) Press [E] to generate a uniform random number.
6. (optional) Press [A] to generate an exponential random number.
7. (optional) Press [f][C] to generate a sample of 20 Exponenaially distributed random numbers that are store in registers R0 to R9 and Rs0 through Rs9.