[simulations] added exercise randomnumbers
This commit is contained in:
@@ -1,8 +1,3 @@
|
||||
% getting familiar with the randn() function:
|
||||
randn(1, 3)
|
||||
randn(3, 1)
|
||||
randn(2, 4)
|
||||
|
||||
% simulate tiger weights:
|
||||
mu = 220.0; % mean and ...
|
||||
sigma = 40.0; % ... standard deviation of the tigers in kg
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
>> normaldata
|
||||
|
||||
ans =
|
||||
|
||||
-0.89120 1.19863 0.95487
|
||||
|
||||
ans =
|
||||
|
||||
-1.10001
|
||||
0.79473
|
||||
0.85979
|
||||
|
||||
ans =
|
||||
|
||||
-1.19206 0.58278 1.70286 -1.28122
|
||||
-0.19966 -1.85623 0.17962 -0.19272
|
||||
|
||||
|
||||
n=100:
|
||||
m=218kg, std= 39kg
|
||||
m=223kg, std= 39kg
|
||||
|
||||
17
simulations/code/randomnumbers.m
Normal file
17
simulations/code/randomnumbers.m
Normal file
@@ -0,0 +1,17 @@
|
||||
% getting familiar with the rand() function:
|
||||
rand(1, 3)
|
||||
rand(3, 1)
|
||||
rand(2, 4)
|
||||
|
||||
% three times the same sequence of 10 random numbers:
|
||||
n = 10;
|
||||
for k = 1:3
|
||||
rand(1, n)
|
||||
end
|
||||
|
||||
% serial corraltion at lag 1:
|
||||
n = 10000;
|
||||
x = rand(n, 1);
|
||||
r1 = corr(x(1:end-1), x(2:end));
|
||||
fprintf('correlation between subsequent random numbers: %.3f\n', r1);
|
||||
|
||||
30
simulations/code/randomnumbers.out
Normal file
30
simulations/code/randomnumbers.out
Normal file
@@ -0,0 +1,30 @@
|
||||
>> randomnumbers
|
||||
|
||||
ans =
|
||||
|
||||
0.740875 0.193576 0.064584
|
||||
|
||||
ans =
|
||||
|
||||
0.061028
|
||||
0.695705
|
||||
0.177097
|
||||
|
||||
ans =
|
||||
|
||||
0.707430 0.404868 0.550246 0.393093
|
||||
0.087565 0.473358 0.247850 0.161137
|
||||
|
||||
ans =
|
||||
|
||||
0.350969 0.340726 0.145924 0.769714 0.203317 0.066427 0.451685 0.959766 0.850558 0.642769
|
||||
|
||||
ans =
|
||||
|
||||
0.145262 0.175168 0.462693 0.089379 0.706870 0.353830 0.604305 0.405531 0.804180 0.253496
|
||||
|
||||
ans =
|
||||
|
||||
0.647119 0.468534 0.484289 0.586001 0.851326 0.972554 0.014812 0.906628 0.982962 0.575003
|
||||
|
||||
correlation between subsequent random numbers: 0.003
|
||||
Reference in New Issue
Block a user