x        = [5.50 5.57 5.42 5.61 5.53 5.47 4.88 5.62 5.63 4.07 5.29 5.34 5.26 5.44 5.46 5.55 5.34 5.30 5.36 5.79 5.75 5.29 5.10 5.86 5.58 5.27 5.85 5.65 5.39]; 
n        = 29;
x_mean   = mean(x);
x_median = median(x);
x_sd     = std(x);

% a) 
histogram(x,12);
title('The density of the earth');
ylabel('Frequency');
% b)
N          = 10000;
sim_mean   = zeros(1, N);
sim_median = zeros(1, N);

for i=1:N 
    x_i           = randsample(x, n, true);
    sim_mean(i)   = mean(x_i);
    sim_median(i) = median(x_i);
end 


% c) 
for i=1:N 
    x_i           = normrnd(x_mean, x_sd, 1, n);
    sim_mean(i)   = mean(x_i);
    sim_median(i) = median(x_i);
end
