Find $E[\sqrt x]$ for $f(x)=e^{-x}$
By the Law of Large Numbers, the sample mean converges to the true expected value as the sample size tends toward infinity.
Numerically, we can solve this by:
>> F = @ (x) sqrt (x).*exp(-x);
>> quad(F,0,50)
ans =
0.886225484979143
or by estimation:
>> x=exprnd(1,1000,1);
>> mean(sqrt(x))
ans =
0.888626070195406
The basic idea of Monte Carlo Integration method is similar to the expectation estimation. By generating continuous uniform random variable x1,x2,...xn and taking the average of g(x1), g(x2),...g(xn) values, we can estimate the integral
\[A=\int\limits_0^1 {g(x)dx} \]
For example, estimate the integral
\[\int\limits_0^1 {\exp ({e^x})dx} \]
Solving numerically, we got
>> F = @ (x) exp ( exp(x));
>> quad(F,0,1)
ans =
6.316563844855637
>> quad(F,0,1)
ans =
6.316563844855637
Compare to the Monte Carlo Integration method
>> x=rand(1000,1);
>> mean(exp(exp(x)))
ans =
6.287779330894578
No comments:
Post a Comment