Using the MATLAB Histogram function, “hist.m”, Illustrate the Central Limit Theorem by taking two different random variables and show how when appropriately scaled and summed, they converge to a Normal (Gaussian) distribution.
The correct answer and explanation is :
Sure! Here’s how you can use MATLAB and the hist function (or histogram, which is preferred in modern MATLAB) to illustrate the Central Limit Theorem (CLT) using two different distributions. We’ll use Uniform and Exponential distributions as our sources of random variables.
โ MATLAB Code
clc; clear;
% Parameters
num_samples = 10000; % Number of summed trials
n = 12; % Number of random variables summed per sample
% Generate Uniform(0,1) random variables
X1 = sum(rand(num_samples, n), 2);
X1 = (X1 - mean(X1)) / std(X1); % Normalize to zero mean, unit variance
% Generate Exponential(1) random variables
X2 = sum(exprnd(1, num_samples, n), 2);
X2 = (X2 - mean(X2)) / std(X2); % Normalize
% Plot histograms
figure;
subplot(1,2,1);
hist(X1, 50);
title('Sum of Uniform(0,1) RVs');
xlabel('Value'); ylabel('Frequency');
subplot(1,2,2);
hist(X2, 50);
title('Sum of Exponential(1) RVs');
xlabel('Value'); ylabel('Frequency');
๐ Explanation (โ300 words)
The Central Limit Theorem (CLT) states that the sum (or average) of a large number of independent and identically distributed (i.i.d.) random variables, regardless of their original distribution, will approximate a Normal (Gaussian) distribution, provided the variables have finite mean and variance.
In the code above, we use two very different types of random variables:
- Uniform(0,1) โ A symmetric distribution with bounded values between 0 and 1.
- Exponential(1) โ A skewed distribution with only positive values, representing events with memoryless properties.
We generate 10,000 independent samples, each being the sum of 12 i.i.d. variables from each distribution. Then, we normalize the results by subtracting the mean and dividing by the standard deviation to compare them on the same scale.
Using the hist function (or histogram in newer MATLAB versions), we plot the histograms of the normalized sums. Visually, both histograms will show bell-shaped curves resembling the standard normal distribution, even though the original distributions are very different in shape.
This behavior directly illustrates the CLT: regardless of whether the original data is uniform, exponential, or something else (as long as it has finite variance), the distribution of the scaled sum will tend toward a Gaussian distribution as the number of summed variables increases.
This concept is crucial in statistics, as it justifies the use of normal distributions in many real-world problems, even when the underlying data isn’t normal.