Start with the joint distribution of $X_1$ and $X_2$, which will be a distribution over the (cartesian) product of the ranges of $X_1$ and $X_2$, i.e. over $(0,\infty)^2$. The area that you're interested in are those points $(x_1,x_2) \in (0,\infty)^2$ with $x_2 > x_1$.
$E[X_2|X_2 > X_1]$ is thus $$\begin{eqnarray}
\int_0^\infty \int_{x_1}^\infty x_2f_1(x_1)f_2(x_2) dx_2x_1
\end{eqnarray}
$$ where $f_1$ and $f_2$ are the densities of your two exponential distributions.
Yes, you can use the exponential distribution to model the time between cars: set it up with the appropriate rate (2 cars/min or 20 cars/min or whatever) and then do a cumulative sum (cumsum
in R) to find the time in minutes at which each car passes. Here's an example in R:
> waits <- rexp(10,2)
> waits
[1] 0.14713730 0.26549532 0.83353238 0.19284503 0.30513264 0.62242778
[7] 0.01943296 0.25699842 0.40801597 0.31635216
> cumsum(waits)
[1] 0.1471373 0.4126326 1.2461650 1.4390100 1.7441427 2.3665704 2.3860034
[8] 2.6430018 3.0510178 3.3673699
Here we have an average of two cars per minute. The first comes at about .15 minutes, the second at .26 minutes after that (i.e., at .41 minutes), and so on. The tenth one comes at 3.36 minutes.
There's another way that doesn't require doing the cumulative sum, though, which may be easier: a Poisson process, which directly generates the times at which cars come. To do it this way, you first sample the total number of cars $n$ that you see in the time interval from a Poisson distribution with parameter Rate*Time (e.g. if you have 2 cars per minute, and your time interval is an hour, your parameter will be 2*60 = 120), and then sample $n$ points from a uniform distribution on the time interval. The result ends up being the same either way. If you want, you can then calculate the waiting times (what you sampled from an Exponential distribution using the first method) by taking the differences between the ordered samples (diff
in R will do this for you).
Here's an example of the alternative approach:
> n <- rpois(10,2*5)
> runif(n,0,5)
[1] 4.3983792 2.0030962 3.6927402 1.5854187 0.3782581 2.0634806 1.0005454
[8] 0.1659071 2.4213297 3.5768906
> diff(c(0,sort(a)))
[1] 0.16590711 0.21235101 0.62228724 0.58487331 0.41767751 0.06038446
[7] 0.35784905 1.15556095 0.11584959 0.70563900
Here, we first sampled $n$, which turned out to be nine, so we're simulating seeing 9 cars in the first 5 minutes (2 cars per minute average). Then we sample the times uniformly from 0 to 5, getting the vector of times. Note that they aren't in order. If we want to get the waiting times back, then we can run the line of code beginning with diff
.
Best Answer
An exponential distribution of a random variable $X$ of expected value $1$ (i.e., mean) has PDF $f_X(x) = e^{-x}$ for $x \gt 0$, and zero otherwise. You want $E(\sqrt{X})$.
In general, to compute $E[(g(X)]$ for a distribution $f_X(x)$ is
$$\int_{-\infty}^{\infty} dx \, g(x) f(x) $$
In your case, the integral is
$$\int_0^{\infty} dx \, \sqrt{x} \, e^{-x}$$
To evaluate the integral, sub $x=y^2$ and get
$$2 \int_0^{\infty} dy \, y^2 \, e^{-y^2} = \int_{-\infty}^{\infty} dy \, y^2 e^{-y^2}$$
The result is, in fact $\sqrt{\pi}/2$.