21 lines
478 B
Matlab
21 lines
478 B
Matlab
% 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
|
|
for n = [100, 10000]
|
|
fprintf('\nn=%d:\n', n)
|
|
for i = 1:5
|
|
x = sigma*randn(n, 1) + mu; % weights of n tigers
|
|
fprintf(' m=%3.0fkg, std=%3.0fkg\n', mean(x), std(x))
|
|
end
|
|
end
|
|
|
|
% plot the data:
|
|
plot(x(1:1000), 'o')
|
|
xlabel('Index')
|
|
ylabel('Weight [kg]')
|