This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/simulations/code/randomnumbers.m

18 lines
335 B
Matlab

% 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 correlation 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);