TITLE: Finding a CDF given a PDF
QUESTION [12 upvotes]: 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!?? $:)$

REPLY [9 votes]: 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.