https://stats.stackexchange.com/questions/447035/inverse-transform-method-with-piecewise-pdf
I have the same question as the one above, which was wasn't answered. I am doing inverse transform sampling with the following pdf:
$$f(x) = \begin{cases}x, & 0 \leq x \leq 1 \\ 2 - x, & 1 < x \leq 2 \end{cases}$$
which gives the cdf
$$F(x) = \begin{cases}\frac{x^2}{2}, & 0 \leq x \leq 1 \\ 2x - \frac{x^2}{2} - 1, & 1 < x \leq 2\end{cases}$$
I know I take the case of $$\frac{x^2}{2} =u$$ and get $$x = \sqrt{2u}, $$
And then for the other case:
$$2x - \frac{x^2}{2} - 1=u $$
$$ - \frac{x^2}{2}+2x - 1-u =0$$
$$\quad \quad x = \frac{-2 \pm \sqrt{4 - 4(-0.5)(-u-1)}}{-1}.$$
$$\quad \quad x = \frac{-2 \pm \sqrt{4 +2(-u-1)}}{-1}.$$
$$\quad \quad x = \frac{-2 \pm \sqrt{2 -2u}}{-1}.$$
$$\quad \quad x = \frac{2 \mp \sqrt{2 -2u}}{1}.$$
I'm unclear what the next step is.