How do I estimation of the means of a random variable?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Zaref Li
le 9 Nov 2021
Réponse apportée : Sulaymon Eshkabilov
le 9 Nov 2021
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 commentaire
Star Strider
le 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.
.
Réponse acceptée
Sulaymon Eshkabilov
le 9 Nov 2021
% 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
mu0=30; % Single Mean value of population
% mu0=[30:20:100]; % A few different mean values of population
sigma0=3.5; % STD
SETs = 1; % How many sets of Population to generate
% SETs = 5; % Five sets of Population to generate in each
% iteration
% Estimation of the mean and variance:
for i = 1 :10
X = normrnd(mu0, sigma0, N, SETs);
m_h(i) = mean(X);
end
% OR without [for .. end] loop, use this one:
X2 = normrnd(mu0, sigma0, N, N);
m_h2 = mean(X2,2);
...
0 commentaires
Plus de réponses (1)
Sulaymon Eshkabilov
le 9 Nov 2021
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')
Voir également
Catégories
En savoir plus sur Random Number Generation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!