18 lines
335 B
Matlab
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);
|
|
|