How do I estimation of the means of a random variable?
Show older comments
Hi everyone. I'm trying to understand this code. Are these operations done for the Gaussian random variable? How do I change the Gaussain random variable? Should I write normrnd() instead of rand()?
% lower and upper bounds of the Uniform random variable X:
a= 0;
b = 2;
% True values of the mean and variance of X:
m = (b-a) / 2;
v = (b-a)^2 / 12;
N = 10; % Number of observations
m_h = zeros(1,N); % Preallocation for speed
% Estimation of the mean and variance:
for i = 1 :10
X = b * rand(N,1);
m_h(i) = sum (X) / N;
end
v_h = v/N;
% Mean value of the estimates:
m_h_mean = sum (m_h,2)/N;
% Demonstrate the results:
disp([ 'Mean value of the estimates is: ',num2str(m_h_mean)])
disp([' True mean value of X is: ',num2str(m)])
stem(m_h)
hold
M = m*ones(1,length(m_h)+2);
plot(0:11,M)
M_h = m_h_mean*ones(1,length(m_h)+2);
plot(0:11,M_h, ' --')
axis([0 10.5 0 2])
1 Comment
Star Strider
on 9 Nov 2021
The rand function creates uniformly-distribured random numbers on the interval [0,1] while randn creates normally distributed random numbers
, so multiplying it changes σ and adding to it changes μ.
Choose the function that returns the desired result.
.
Accepted Answer
More Answers (1)
In order to generate a normally distributed random numbers, you can employ
clc; clearvars; close all
Npop = 7.5e2; % Population size
mu0=30; % Mean value of population
sigma0=3.5; % STD
SETs = 3; % How many sets of Population to generate
P0 = normrnd(mu0, sigma0, Npop, SETs);
histfit(P0(:,1), 30, 'normal'), title('One Set of Population')
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!