Distribution of a function of a random variable and the steps/range that is needed to take. The Question that I need to solve is:
Let $X\sim~\text{Unif}[-1,2]$. Find the probability density function of the random variable $Y = X^2$.
Now I have solved it as follows, but the steps I have to take after that are unclear to me. I need to find some kind of range and take 'certain?' steps, and I just do not know how big of steps I have to take or what is most logical.
$F_Y(y) = P(Y \leq y) = P(X^2\leq y) = P(\sqrt y  \leq x \leq \sqrt -y) = F_X(\sqrt y) - F_X(\sqrt-y) $
Now you take derivative and you get
$f_y(y) = \frac{1}{2 \sqrt y} f_X(\sqrt y) + \frac{1}{2 \sqrt y} f_X(\sqrt -y) $.
So, I made a drawing of the uniform distribution and because of $Y=X^2$ it goes from $[0,2]$. I know that for $y < 0, f_Y(y) = 0.$ But what do I need to do next? How do I know how much steps I need to take (in this case two more, but why?) and how big must those steps be? Which ranges are important? How do I find those?
 A: We have that $X \in [-1, 2]$.
Consider the graph $Y = X^2$. This is not a one-to-one function. (Observe that for $X \in [-1, 1]$ that there are two $X$ values that yield the same $Y$ value.)
Now, by definition, for each $y \in \mathbb{R}$,
$$F_{Y}(y) = \mathbb{P}(Y \leq y) = \mathbb{P}(X^2 \leq y)\text{.}$$
Partition the values of $Y$ into the following:

*

*If $y < 0$, obviously $F_{Y}(y) = 0$.

*Suppose $0 \leq y \leq 1$ (since this corresponds to where $X \in [-1, 1]$; i.e., $Y$ is not one-to-one). Choose any $y$ between $0$ and $1$ inclusive and plot the line $Y = y$; it follows that $X^2 \leq y$ if and only if $-\sqrt{y} \leq X \leq \sqrt{y}$. Hence, $$
\begin{align}
F_{Y}(y) &= \mathbb{P}(X^2 \leq y) \\
&= \mathbb{P}(-\sqrt{y} \leq X \leq \sqrt{y}) \\
&= F_{X}(\sqrt{y})-F_{X}(-\sqrt{y}) \\
&= \dfrac{\sqrt{y}-(-1)}{2-(-1)} - \dfrac{-\sqrt{y}-(-1)}{2-(-1)} \\
&= \dfrac{\sqrt{y}+1}{3} + \dfrac{\sqrt{y}-1}{3} \\
&= \dfrac{2\sqrt{y}}{3}\text{.} 
\end{align}$$

*Now suppose $1 < y \leq 4$ (where $X \in (1, 2]$). Then
$$\{X^2 \leq y\}  = \{X^2 \leq 1\} \cup \{1 < X^2 \leq y\}\text{.}$$
It follows that
$$\begin{align}
F_{Y}(y) &= \mathbb{P}(X^2 \leq 1) + \mathbb{P}(1 < X^2 \leq y) \\
&= F_{Y}(1) + \mathbb{P}(1 < X < \sqrt{y}) \\
&= \dfrac{2\sqrt{1}}{3} + F_{X}(\sqrt{y}) - F_{X}(1) \\
&= \dfrac{2}{3}+\dfrac{\sqrt{y} - (-1)}{2-(-1)} - \dfrac{1-(-1)}{2-(-1)} \\
&= \dfrac{2}{3}+\dfrac{\sqrt{y}+1}{3} - \dfrac{2}{3} \\
&= \dfrac{\sqrt{y}+1}{3}\text{.}
\end{align}$$

*If $y > 4$, obviously $F_{Y}(y) = 1$.

Hence, the density is given by the derivative of $F_Y$, or
$$f_{Y}(y) = \begin{cases}
\dfrac{1}{3\sqrt{y}}, & 0 \leq y \leq 1 \\
\dfrac{1}{6\sqrt{y}}, & 1 < y \leq 4 \\
0, & \text{otherwise.}
\end{cases}$$
