1D Moments & Expectations

Learn More

Expectation as a weighted average

$$\mathrm{E}[g(X)] = \int_{-5}^{5} g(x)p(x)\,\mathrm{d}x.$$

High-density regions matter most. Plot 3 shows each interval's signed contribution; plot 4 adds them from left to right and ends at the expectation.

  • $g(x)=x$: mean $\mu$
  • $g(x)=x^k$: raw moments
  • $g(x)=(x-\mu)^k$: central moments, e.g. variance for $k=2$
  • $g(x)=1$: total probability

Densities are renormalized on $[-5,5]$. The δ-like density is a Gaussian with $\sigma=0.02$, so $\mathrm{E}[g(X)]\approx g(\text{location})$. Dragging adds local, linearly interpolated edits to the chosen function. The integral uses 2000 midpoint cells.