# Finding a CDF given a PDF

The PDF for $Y$ is $$f_Y(y) = \begin{cases} 0 & |y|> 1 \\ 1-|y| & |y|\leq 1 \end{cases}$$

How do I find the corresponding CDF $F_Y(y)$? I integrated the above piecewise function to get $$F_Y(y)=\begin{cases} 1/2 -y/2-y^2/2 & [-1,0] \\ 1/2-y/2+y^2/2 & [0,1] \end{cases}$$ by using the fact that $F_Y(y)=\int _{-\infty}^{y}{f_Y(y)}\,dy$, however my text claims the answer is $$F_Y(y)=\begin{cases} 1/2 +y+y^2/2 & [-1,0] \\ 1/2+y-y^2/2 & [0,1] \end{cases}$$ I am struggling with pdf and cdfs, so I asssume I did something wrong other than the simple integration. Who's correct? Me or the Text!?? $:)$

-
HINT:Does you solution have the property $F_Y(-1) = 0$ and $F_Y(1) = 1$ ? –  Sasha Mar 11 '12 at 1:47
It does not, and I know those are properties my answer should have. But why should my answer have to be fiddled with if I used the definition of the cdf? –  cap Mar 11 '12 at 1:50
You probably did the integration wrong, and were too distracted by your struggle with PDFs and CDFs to notice :) By the way, I edited your answer to use \begin{cases}...\end{cases}, which is a better way to typeset piecewise functions. Feel free to click 'edit' to see what I did and use it in the future. –  Rahul Mar 11 '12 at 1:53
@Sasha I found my mistake. I had forgot about that fact and I could've used it to find my constants of integration, but for some reason I integrated by actually breaking up the graph to find the areas. –  cap Mar 11 '12 at 1:58
@RahulNarain, is there a software I can download to type in TeX for practice and HW, etc? Thanx –  cap Mar 11 '12 at 1:59

We have that $F(y) = \displaystyle \int_{-\infty}^y f(x) dx$. In your case, we are given that $$f(x) = \begin{cases} 0 & x <-1\\ 1 + x & x \in[-1,0]\\ 1-x & x \in [0,1]\\ 0 & x > 1\end{cases}$$

• If $y < -1$, then we have $F(y) = \displaystyle \int_{-\infty}^y f(x) dx = \displaystyle \int_{-\infty}^y 0 dx =0$. We have the integrand $f(x) = 0$ since $x \leq y < -1$.
• If $y \in [-1,0]$, then we have $F(y) = \displaystyle \int_{-\infty}^y f(x) dx = \displaystyle \int_{-\infty}^{-1} f(x) dx + \displaystyle \int_{-1}^{y} f(x) dx$. Since, $f(x) = 0$ for all $x < -1$, we get that $$F(y) = \displaystyle \int_{-\infty}^y f(x) dx = \displaystyle \int_{-1}^{y} f(x) dx = \displaystyle \int_{-1}^{y} \left( 1+x \right) dx = \left( x + \frac{x^2}{2} \right)_{-1}^{y}$$ $$F(y) = \left(y + \frac{y^2}{2} \right( - \left( -1 + \frac12 \right) = \frac12 + y + \frac{y^2}{2}.$$
• If $y \in [0,1]$, then we have $F(y) = \displaystyle \int_{-\infty}^y f(x) dx = \displaystyle \int_{-\infty}^{-1} f(x) dx + \displaystyle \int_{-1}^{0} f(x) dx + \displaystyle \int_{0}^{y} f(x) dx$. Since, $f(x) = 0$ for all $x < -1$, we get that $$F(y) = \displaystyle \int_{-1}^{0} f(x) dx + \displaystyle \int_{0}^{y} f(x) dx = \displaystyle \int_{-1}^{0} \left( 1+x \right) dx + \displaystyle \int_{0}^{y} (1-x) dx$$ Hence, $$F(y) = \frac12 + \left( x - \frac{x^2}{2}\right)_0^{y} = \frac12 + y - \frac{y^2}{2}$$
• For $y > 1$, since $f(x) = 0$ for all $x>1$, we have that $F(y) = F(1)$ for all $y > 1$. Hence, $F(y) = F(1) = 1$.

Hence, $$F(y) = \begin{cases} 0 & y <-1\\ \frac12 + y + \frac{y^2}{2} & y \in[-1,0]\\ \frac12 + y - \frac{y^2}{2} & y \in[0,1]\\ 1 & y > 1\end{cases}$$

-

This is the kind of problem that gives integration a bad name among students.

• Draw a graph of the density function. It looks like an isoceles right triangle with hypotenuse $2$ and apex at $(0,1)$ and very obviously has area $1$ (useful as a check on one's work.)

• For any $x_0$, $F(x_0)$ is the area under the density function to the left of $x_0$. It should be obvious that $F(x_0) = 0$ if $x_0 \leq -1$ and $F(x_0) = 1$ if $x_0 > 1$.

• Pick an $x_0$ in $[-1,0]$. The area to the left of $x_0$ is a right triangle with altitude $1+x_0$ and base $1+x_0$ (or $x_0 - (-1)$ if you like, and so $F(x_0) = \frac{1}{2}(1+x_0)^2$. Quick check: value is $\frac{1}{2}$ at $x_0 = 0$ and $0$ at $-1$.

• Pick an $x_0$ in $[0,1]$. By symmetry, the area to the right of $x_0$ is $\frac{1}{2}(1-x_0)^2$. Quick check: value is $\frac{1}{2}$ at $x_0 = 0$ and $0$ at $1$. Hence, $F(x_0) = 1 - \frac{1}{2}(1-x_0)^2$.

Putting it all together, we get the same answer as Sivaram Ambikasaran. It takes longer to write out the instructions than to just work off the diagram.

-
Nice answer. I like the fact that you try and avoid integration as much as you can. +1. :-) –  user21436 Mar 11 '12 at 5:17
@KannappanSampath Thanks. Since I taught probability over many years to recalcitrant engineering students who invariably fail to distinguish between antiderivatives and integrals, I like to keep things as simple and visual as possible. Understanding and remembering $F(x)$ as the area under $f(x)$ to the left of $x$ is easier than wondering what is this strange $t$ that suddenly showed up in $$F(x) = \int_{-\infty}^x f(t)\mathrm dt$$ and how $f(x) and$f(t)$are related. Trivial to a mathematician; difficult for an engineering student to whom calculus is a dimly remembered haze of formulas. – Dilip Sarwate Mar 11 '12 at 11:46 First work with$y\le 0$to obtain $$F_Y(y)=\int_{-1}^y 1-|u|du=\int_{-1}^y 1+u du=y-(-1)+\frac{y^2-(-1)^2}{2}=\frac{1}{2}+y+\frac{1}{2}y^2$$ Now work with$1\ge y\ge0$by splitting (using the fundamental theorem of calculus) $$F_Y(y)=\int_{-1}^y f_Y(u)du=F_Y(0)+\int_0^y 1-u du$$ Now figure out what$F_Y$must be for$y\le-1$and$y\ge+1\$...

-