Many problems in science, economics, finance, and so on require us to compute conditional expectations. If

and

are

random variables with nice density, then the conditional expectation

can be defined as the orthogonal projection of

on the linear subspace space of all functions of

in Hilbert space of all

(square-integrable) random variables. Thus the conditional expectation can be though of as a function of

with the minimum

distance from

. This justifies the well-known Monte Carlo method of approximating

by generating a sample of (

,

) pairs and regressing

on

by solving a least-squares problem for a polynomial of some chosen degree. In this Demonstration we start with two independent random variables

and

with uniform distribution on [0,1]. As

we take a random variable

for some positive integers

,

, and

. In this case

*Mathematica* is able to compute the exact formula for

, so that we can assess the accuracy of the estimate by computing the

norm using numerical integration.

K. L. Judd,

*Numerical Methods in Economics*, Cambridge, MA: The MIT Press, 1998.