How do I estimation of the means of a random variable?

9 次查看(过去 30 天)
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 个评论
Star Strider
Star Strider 2021-11-9
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.
.

请先登录,再进行评论。

采纳的回答

Sulaymon Eshkabilov
% 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);
...

更多回答(1 个)

Sulaymon Eshkabilov
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')

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by