[simulations] added exponential distribution

This commit is contained in:
2020-12-27 23:15:19 +01:00
parent 5e9ad55d1c
commit a50cc4ff7b
6 changed files with 77 additions and 5 deletions

View 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);

View 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

View 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);

View File

@@ -0,0 +1 @@
Of 20 coin flips, 12 heads showed up.