フィルターのクリア

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

5 ビュー (過去 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 Center および File ExchangeWaveform Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by