# Monte Carlo Integration

$$I = \int_a^b f(x) \, dx$$

---

## Riemann Integration

Pick $x_i = hi + a$

$$I = \sum_{i=1}^{n} f(x_i) \frac{b-a}{n}$$

This isn't the only way to integrate.

---

## Monte Carlo Integration

Sample $X \sim U[a,b]$

$$\hat{I} = \frac{b-a}{n} \sum_{i=1}^{n} f(x_i)$$

> *This is technically a random variable.*

### Expectation of the Estimator

$$E\{f(x)\} = \int_a^b f(x) \cdot U[a,b] \, dx = \int_a^b f(x) \frac{1}{b-a} \, dx = \frac{1}{b-a} \int_a^b f(x) \, dx$$

$$E\{\hat{I}\} = \frac{b-a}{n} \sum_{i=1}^{n} E\{f(x)\}$$

$$= \frac{b-a}{n} \sum_{i=1}^{n} \left( \frac{1}{b-a} \int_a^b f(x) \, dx \right)$$

$$= \frac{b-a}{n} \cdot \frac{n}{b-a} \int_a^b f(x) \, dx$$

$$E\{\hat{I}\} = \int_a^b f(x) \, dx$$

**Key insight:** The Monte Carlo estimator is unbiased — its expected value equals the true integral.

---

## Multi-Dimensional Case

$$I = \iiint f(\vec{x}) \, d\vec{x}$$

$$\hat{I} = \frac{V}{n} \sum_{i=1}^{n} f(\vec{x}_i)$$

where $V$ is the volume of the integration region.
