% ——————————————————————————-
% This Matlab code allows you to verify the Central Limit Theorem (CLT)
% The population is normal with mean = true_mean and variance = true_variance
% ——————————————————————————-
Copyright By PowCoder代写 加微信 powcoder
% clean up the environment
% sample size
sample_size = 100000; % Choose the number of observations for each sample
smaller_sample_size = 1000; % Choose the number of observations for each (smaller) sample
number_of_samples = 1000; % Choose the number of samples
% population parameters
true_mean = 2; % mean of the population
true_variance = 1; % variance of the population
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%—————————————————————————————————————–
% The CLT for the mean WITHOUT standardization –
% as the number of observations increases, the distribution of the “sample” mean
% becomes more and more concentrated around the “population” mean –
% In fact, the variance of the sample mean goes to zero (see slides for Lecture 1)
%—————————————————————————————————————–
% initialize vectors
small_sample = ones(smaller_sample_size, number_of_samples);
sz = size(small_sample);
larger_sample = ones(sample_size, number_of_samples);
sz1 = size(larger_sample);
% create small and large samples
X_small = random(‘Normal’, true_mean, sqrt(true_variance), sz);
X_large = random(‘Normal’, true_mean, sqrt(true_variance), sz1);
% compute the mean of each sample
mean_small = mean(X_small);
mean_large = mean(X_large);
% plot the distribution of the sample means
histogram(mean_small,’normalization’,’pdf’, “FaceColor”, “red”);
histogram(mean_large,’normalization’,’pdf’, “FaceColor”, “blue”);
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com