How to calculate $E [Z^2]$ when $E[Z]$ is known? For the following calculation, why $E[Z_1^2] = \pi/4$ ? In general, how to calculate $E[Z^2]$ ? Thanks much.

3 down vote

Let's also elaborate on Ross Millikan's answer, adapted to the case f(x)=1−x2−−−−−√, 0≤x≤1. Suppose that $(X1,Y1),(X2,Y2),\ldots$is a sequence of independent uniform vectors on $[0,1]\times [0,1]$, so that for each $i$, $X_i$ and $Y_i$ are independent uniform $[0,1]$ random variables. Define $Z_i$ as follows: $Z_i=1$ if $X_i^2+Y_i^2 \le 1$, $Z_i=0$ if $X_i^2+Y_i^2 &gt; 1$, so the $Z_i$ are independent and identically distributed random variables, with mean $\mu$ given by
$ \mu = E[Z_1] =P[X_1^2+Y_1^2 \le 1]=P[(X_1,Y_1) \in \{(x,y) \in [0,1]^2 : x^2+y^2 \le 1\}]  = \pi/4$,
where the last equality follows from $P[(X1,Y1)\in A]=\text{area}A (A \subset [0,1]^2)$.

By the strong law of large numbers, the average Zˉn=∑ni=1Zin converges, with probability 1, to the expectation μ as n→∞. That is, with probability 1, Zˉn→π/4 as n→∞.

To get a probabilistic error bound, note first that the $Z_i$ have variance $\sigma^2$ given by
$\sigma^2=\text{Var}[Z_1]=E[Z_1^2]−E^2[Z_1]=\pi /4−(\pi /4)^2=\pi /4 (1−\pi /4)&lt;10/59$.
Elaborating on my (second, according to date) answer from Approximating $\pi$ using Monte Carlo integration.

Suppose that $(X_1,Y_1)$ is a uniform vector on $[0,1] \times [0,1]$, so that $X_1$ and $Y_1$ are independent uniform$[0,1]$ random variables. Define $Z_1$ as follows: $Z_1 = 1$ if $X_1^2 + Y_1^2 \leq 1$, $Z_1 = 0$ if $X_1^2 + Y_1^2 &gt; 1$. Then, 
$$
{\rm E}[Z_1] = 1 \cdot {\rm P}[X_1^2 + Y_1^2 \leq 1] + 0 \cdot  {\rm P}[X_1^2 + Y_1^2 &gt; 1] = {\rm P}[X_1^2 + Y_1^2 \leq 1].
$$
Similarly,
$$
{\rm E}[Z_1^2] = 1^2 \cdot {\rm P}[X_1^2 + Y_1^2 \leq 1] + 0^2 \cdot  {\rm P}[X_1^2 + Y_1^2 &gt; 1] = {\rm P}[X_1^2 + Y_1^2 \leq 1].
$$
Hence, ${\rm E}[Z_1^2] = {\rm E}[Z_1] $. 
Next, note that $X_1^2 + Y_1^2 \leq 1$ if and only if $(X_1,Y_1)$ belongs to the set $A \subset [0,1]^2$ defined by 
$$
A = \lbrace (x,y) \in [0,1]^2 : x^2+y^2 \leq 1\rbrace.
$$
Thus,
$$
{\rm E}[Z_1^2] = {\rm P}[X_1^2 + Y_1^2 \leq 1] = {\rm P}\big[(X_1,Y_1) \in A].
$$
However, ${\rm P}[(X_1,Y_1) \in A] = {\rm area}A$, and ${\rm area}A = \pi/4$ (recall that the area of a disc of radius $1$ is $\pi$); hence ${\rm E}[Z_1^2] = \pi/4$.
An expectation operator is a basically integration. Provided you know the p.d.f. of a random variable $Z$, $f(z)$,
$$E(Z)=\int z f(z) dz$$
and
$$E(Z^{2})=\int z^2 f(z) dz $$
over the support (the interval of z in which $f(z)$ is positive) of $z$.