# From where did the $(2-w)^2$ come?

Let X, Y be independent random variables each with the uniform distribution on the interval [0, 1].

Compute the cumulative density function of $W = X + Y$

I know that when $1<w<2$, we have to compute the trapezoid with the given vertices, but in fact shouldn’t a trapezoid have 4 vertices instead of 5 $(0, 0)$;$(1, 0)$;$(0,1)$;$(w-1,1)$ and $(1, w-1)$ and I thought then it might be calculated as 1- the area of the triangle above $x+y$ but from where did we get the $(w-2)^2$?

• I believe that you mean the cumulative density function, since the probability density function is clear from the definition of $W$ and the distributions of $X$ and $Y$. (And in fact, is the first thing shown in your image!) – rwbogl Jul 23 '18 at 0:37
• Yes I mean in the cumulative density function – Roy Rizk Jul 23 '18 at 0:38
• Discussion and plots in my answer are intended to help you visualize the steps in the analytical solution. // Meanwhile, @rwbogl (+1) gave a nice start on the details of the analytical solution, which I hope your will Accept. Try plotting the formulas for the CDF and PDF when you get them. // Also, perhaps edit a little of your own work into your Question to keep it from being 'Closed'. – BruceET Jul 23 '18 at 1:22

You are right that the shape described in the text is not a trapezoid. It is an irregular pentagon. You can see it in the lower left portion of the square in the figure below.

As you said, the area of this pentagon is the area of the square (which is $1$) minus the area of the triangle in the upper right corner. The legs of the triangle have length $2 - w$ because $$1 - (w - 1) = 2 - w.$$

Also notice that if $w = 2,$ the only possible $x,y$ value is $(1,1),$ which is consistent with shrinking the triangle down to a single point (leg length $0$), whereas if $w = 1$ then we could have $(x,y) = (0,1)$ or $(x,y) = (1,0)$ or anything on the segment between those points--in other words, a triangle with legs of length $1$ covering half of the square. For $1 < w < 2$ we get something in between, like the triangle shown in the figure.

Let's trace out what your image says.

Set $W = X + Y$, where $X, Y \sim \text{Uniform}(0, 1)$. We want to find the c.d.f. of $W$; call this $F_W$.

By definition, $$F_W(w) = P(W \leq w) = \int_{R_w} dx dy,$$ where $R_w$ is the intersection of $\{(x, y) \mid x + y \leq w\}$ and $[0, 1]^2$. That is, everything in the unit square with $x + y \leq w$.

As mentioned, the nature of this region changes for different $w$. If we draw a picture (draw it!), we can see that the region is a triangle for $0 \leq w \leq 1$, and a trapezoid when $1 < w < 2$. Further, if we label our picture a little (label it!), we can see that the vertices are what the image says.

To integrate this trapezoidal region, we need two integrals: $$\int_{R_w} dx dy = \int_0^{w - 1} \int_0^1 dy dx + \int_{w - 1}^1 \int_0^{w - x} dy dx.$$

Evaluating these gives $- \frac{w^{2}}{2} + 2 w - 1$, which is equal to the given expression for the case $1 < w < 2$.

Quoting from the posted information for finding $P(W \le w):$ When $0 < w \le 1,$ the region $R_w$ is a triangle with vertices $(0,0), (0, w),$ and $(w, 0).$ Then this triangle has area $w^2/2.$ Because the distribution of $X$ and $Y$ is uniform on the square with vertices $(0,1)$ and $(1,1),$ probabilities are proportional to areas. Thus $P(W \le w) = w^2/2,$ for $0 < w \le 1.$

If you want the density function, then differentiate the CDF, first for $0 < w < 1$ and then for $1 <w \le 2.$

A simulation of 50,000 values of $W$ makes it easy to show some areas, the PDF and the CDF. In the figure below, the first plot shows (red) the area corresponding to $P(X < 0.5);$ the second shows (green) the area corresponding to $P(W < 1.6);$ the third shows the empirical CDF, which suggests the shape of the CDF of $W$ you are asked to compute; and the fourth shows a histogram of simulated values of $W.$ which suggests the triangular shape of the density function of $W.$

The empirical CDF (ECDF) jumps up by $1/50,000$ at each observed value of $W.$ Usually, an ECDF gives a more precise indication of the CDF than a histogram gives of the PDF (because information is lost when data are put into histogram bins).

par(mfrow=c(2,2))  # enables 4 panels per plot
m = 50000;  x = runif(m);  y = runif(m);  w = x+y
plot(x, y, pch=".", main="Joint Dist'n of X and Y with P(W < .5)")
points(x[w < .5], y[w < .5], pch=".", col="red")  # read [] as 'such that'
plot(x, y, pch=".", main="Joint Dist'n of X and Y with P(W < 1.6)")
points(x[w < 1.6], y[w < 1.6], pch=".", col="green2")
plot(ecdf(w), main="Emplrical CDF of Observed Values of W")  # 'ecdf' procedure
hist(w, prob=T, col="skyblue2", main="Histogram of Observed Values of W")
par(mfrow=c(1,1))


Notes: points puts points onto an existing plot. ecdf includes data sort and and cumulative tally, then returns x and y values ready for plotting (actually a stair-step plot but seems a curve with 50,000 points at this resolution); argument prob=T of hist function invokes vertical density scale.

• This is an amazing empirical answer for this question. How are you estimating the c.d.f. numerically? – rwbogl Jul 23 '18 at 1:27
• Thanks, easy in R. I'll clean up the code and post it as an addendum – BruceET Jul 23 '18 at 1:29