[simulations] added exponential distribution
This commit is contained in:
8
simulations/code/exprandom.m
Normal file
8
simulations/code/exprandom.m
Normal file
@@ -0,0 +1,8 @@
|
||||
n = 10000;
|
||||
lambda = 50.0; % event rate
|
||||
t = exprnd(1.0/lambda, n, 1); % exponentially distributed random numbers
|
||||
m = mean(t); % mean time interval
|
||||
s = std(t); % corresponding standard deviation
|
||||
fprintf('Generated n=%d exponentially distributed random time intervals\n', n);
|
||||
fprintf(' with rate=%.0fHz (-> mean=%.3fs, std=%.3fs)\n', lambda, 1.0/lambda, 1.0/lambda);
|
||||
fprintf('Measured mean=%.3fs, std=%.3fs\n', m, s);
|
||||
3
simulations/code/exprandom.out
Normal file
3
simulations/code/exprandom.out
Normal file
@@ -0,0 +1,3 @@
|
||||
Generated n=10000 exponentially distributed random time intervals
|
||||
with rate=50Hz (-> mean=0.020s, std=0.020s)
|
||||
Measured mean=0.020s, std=0.020s
|
||||
6
simulations/code/probability.m
Normal file
6
simulations/code/probability.m
Normal file
@@ -0,0 +1,6 @@
|
||||
n = 20; % number of coin flips
|
||||
P = 0.6; % probability of head
|
||||
u = rand(n, 1); % n random numbers between 0 and 1
|
||||
heads = u < P; % true if head showed up
|
||||
nheads = sum(heads); % number of heads
|
||||
fprintf('Of %d coin flips, %d heads showed up.\n', n, nheads);
|
||||
1
simulations/code/probability.out
Normal file
1
simulations/code/probability.out
Normal file
@@ -0,0 +1 @@
|
||||
Of 20 coin flips, 12 heads showed up.
|
||||
Reference in New Issue
Block a user