找到你要的答案

Q:Normal distribution realizations [duplicate]

Q:正态分布实现[复制]

This question already has an answer here:

Hi I am trying to generate values using Matlab for the question below:

Let x be a random variable with distribution N(0,1). Determine in an exact or approximate way:

E{x^2}

X=[-5:5];
Y=normpdf(X);
x2=X.*X;
ex2=sum(x2.*Y);

I get the answer 1 which I assume is correct. But when I increase the realizations of X, i.e.

X=[-5:0.5:5];
Y=normpdf(X);
x2=X.*X;
ex2=sum(x2.*Y);

I get the answer as 2. Am I going wrong somewhere?

这个问题在这里已经有了答案:

你好,我想用MATLAB对以下问题产生价值:

设X是一个随机变量分布N(0,1)。精确地或近似地确定:

e { x 2 }

X=[-5:5];
Y=normpdf(X);
x2=X.*X;
ex2=sum(x2.*Y);

我得到的答案1,我认为是正确的。但当我增加X的实现时

X=[-5:0.5:5];
Y=normpdf(X);
x2=X.*X;
ex2=sum(x2.*Y);

我得到的答案是2。我哪里出错了?

answer1: 回答1:

You are numerically computing the second moment of a Gaussian random variable. That's expressed in terms of the pdf as an integral, which you approximate by a sum.

To approximate the integral by a sum, you need to multiply by the sampling step used on the x axis. (you can think that the "dx" in the integral is replaced by a non-infinitesimal "Δx"). The step is 1 in the first case, and 0.5 in the second.

So you need to multiply your second result by the step 0.5.

数值计算高斯随机变量的第二时刻。这是作为一个整体在PDF的形式表达,你近似的总和。

用一个求积分的方法,你需要乘以X轴上所用的采样步长。(你可以认为“DX”的整体是由一个非无穷小”ΔX”代替)。第一步是1步,第二步是0.5。

因此,您需要乘以您的第二个结果的步骤0.5。

matlab  probability  normal-distribution