Note that this question has two parts: a) where I describe the method I am using and b) the example I do not understand.
a)
Let's say that I want to estimate the following integral: $$\int_0^{\pi/4} \frac{x \sin^2(x)}{\cos(x)} dx$$ The idea is that we can write an unknown quantity as an expectation and then approximate it using a sample average relying on the law of large numbers. And so, this integral can be written as: $$E\left[\frac{X \sin^2(X)}{\cos(X)} \right] $$ where $X$ is the uniformly distributed random variable, $X \sim U(0,\frac{\pi}{4}) $. Then the idea would be to:
- Choose large number of replications $n$ and choose linear congruential generator (LCG)
- For $i=0,\dotsc,n$:
- Generate $U_i \sim U(0,1)$ using the LCG and calculate $X_i = \frac{\pi}{4}U_i$
- Calculate $\frac{X_i \sin^2(X_i)}{\cos(X_i)}$
- Output $\bar{X} = \frac{1}{n} \sum_{i=0}^n \frac{X_i \sin^2(X_i)}{\cos(X_i)} $
b)
I am quite confident in this method. However, I have another example that I find rather troublesome. The idea is the same - estimate the numerical value of the integral: $$\int_0^{\pi/2} e^{\sin^2(x)} dx$$ In the solution that I have been provided with it states that we can treat $X \sim U(0,\frac{\pi}{2})$ BUT in this example instead of writing the expectation as in first example: $$E\left[e^{\sin^2(X)} \right] $$ Rather, I am supposed to notice that I can write the integral as: $$\int_0^{\pi/2} e^{\sin^2(x)} \frac{\pi}{2} \frac{2}{\pi}dx$$ And then write the integral as:
$$E\left[e^{\sin^2(X)}\frac{\pi}{2} \right]$$ Then the process of estimating the integral follows the one in initial example.
I'm afraid I do not follow the logic in the second example. Why do I need to add the $\frac{\pi}{2}$ term here?
Suppose we want to approximate the integral: $$ \int_a^b f(x)\,dx. $$ If $X\sim U[a,b]$, i.e., it is a uniform random variable on $[a,b]$, the expectation of $f(X)$ is given by $$ \mathsf{E}f(X)=\int_a^b \frac{f(x)}{b-a}\, dx. $$ (assuming that $\mathsf{E}|f(X)|<\infty$.) If $\{X_i\}_{i\ge 1}$ are independent copies of $X$, by the strong law of large numbers, $$ \frac{(b-a)}{n}\sum_{i=1}^n f(X_i)\to (b-a)\mathsf{E}f(X)=\int_a^b f(x)\,dx \quad\text{a.s.}, $$ as required.