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

조회 수: 8 (최근 30일)
Zaref Li
Zaref Li 2021년 11월 9일
답변: Sulaymon Eshkabilov 2021년 11월 9일
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
Sulaymon Eshkabilov 2021년 11월 9일
% 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
Sulaymon Eshkabilov 2021년 11월 9일
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')
  댓글 수: 1
Zaref Li
Zaref Li 2021년 11월 9일
but I want to make changes on the code I shared in the question.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Waveform Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by