Transformation of Random Variable $Y = X^2$

Let's start by seeing what the density function $f_X$ of $X$ tells us about the cumulative distribution function $F_X$ of $X$. Since $f_X(x) = 0$ for $-\infty < x < -1$, we see that $$F_X(x) = \int_{-\infty}^x f_X(t) \, dt \equiv 0 $$ in this range. Similarly, since $f_X(x) = 0$ in the range $2 < x < \infty$, we see that $$F_X(x) = \int_{-\infty}^x f_X(t) \, dt = \int_{-\infty}^{\infty} f_X(t) \, dt \equiv 1$$ in this range. In other words, the random variable is "supported on the interval $[-1,2]$" in the sense that $P(X \notin [-1,2]) = 0$.

Now let us consider $Y = X^2$. This variable is clearly non-negative and since $X$ is supported on $[-1,2]$, we must have that $Y$ is supported on $[0, \max((-1)^2,2^2)] = [0,4]$. This is intuitively clear because the variable $X$ (with probability $1$) takes values in [-1,2] and so $X^2$ takes values in $[0,\max((-1)^2,(2)^2)]$. So we only need to understand $F_Y(y)$ in the range $y \in [0,4]$. Now, we always have

$$ F_Y(y) = P(Y < y) = P(X^2 < y) = P(-\sqrt{y} < X < \sqrt{y}) = \int_{-\sqrt{y}}^{\sqrt{y}} f_X(t) \, dt $$

but since $f_X$ is defined piecewise, to proceed at this point we need to analyze several cases. We already know that $F_Y(y) = 0$ if $y \leq 0$ and $F_Y(y) = 1$ if $y \geq 4$.

If $0 \leq y \leq 1$ then $[-\sqrt{y},\sqrt{y}]$ is contained in $[-1,1]$ and on $[-1,1]$ the density function is $f_X(x) = \frac{1}{3}x^2$ so we can write

$$ F_Y(y) = \int_{-\sqrt{y}}^{\sqrt{y}} \frac{1}{3} t^2 \, dt. $$

However, if $1 < y \leq 4$ then $-\sqrt{y} < -1$ and so the interval of integration splits as $[-\sqrt{y}, -1] \cup [-1,\sqrt{y}]$. Over the left $[-\sqrt{y},-1]$ part, the density function is zero so the integal will be zero and we are left only with calculating the integral over the right part:

$$ F_Y(y) = \int_{-\sqrt{y}}^{-1} f_X(t) \, dt + \int_{-1}^{\sqrt{y}} f_X(t) \, dt = \int_{-1}^{\sqrt{y}} \frac{1}{3}t^2 \, dt. $$


If the square of a number is between $0$ and $1$ then the number itself has to be between $-1$ and $1$. Like, the squares of $-0.5$ and $0.5$ are both $0.25$. However, no real number will produce negative squares. This is independent of the nature of the number, it can be a fixed one or a randomly selected one. So,

$$P(X^2<y)= \begin{cases} 0&\text{ if }& \ y<0\\ P(-\sqrt y < X <\sqrt y)&\text{ if }& 0\leq y<1 \end{cases}.$$

If $y\geq 1$ then the square of every number between $-1$ and $\sqrt y$ will be less than $ y$. So

$$P(X^2<y)=P(-1<X<\sqrt y).$$ If, however, $y\geq 4$ then the square of any number between $-1$ and $2$ will be less than $y$, that is

$$P(X^2<y)=1$$ if $y\geq 4$ because all of our random numbers are less than two; their squares are less than $4$.

This is why

$$P(X^2<y)= \begin{cases} 0&\text{ if }& \ y<0\\ P(-\sqrt y < X <\sqrt y)&\text{ if }& 0\leq y<1\\ P(-1 < X <\sqrt y)&\text{ if }& 1\leq y<4\\ 1&\text{ if }&y\geq 4. \end{cases}$$

The rest is given by integrating the pdf over the respective domains.