I have a probability density function:
$f(x) = \begin{cases} \frac 1 4xe^{\frac {-x}2}, & x\ge0 \\ 0, & x < 0\end{cases}$
To add more detail, cdf is:
$F(x) = \begin{cases} 1+\frac{-1}2xe^{\frac {-x}2}-e^{\frac {-x}2}, & x\ge0 \\ 0, & x < 0\end{cases}$
Find the $Med(x)$.
Solving
$$\int_{-\infty}^{x} f(x) dx=1+\frac{-1}2xe^{\frac {-x}2}-e^{\frac {-x}2}=\frac 12$$
I found 2 values $3.3567$ and $-1.5361$, and my book said that the answer is $-1.5361$. This is confusing because I thought $Med(X)\ge 0$.
Your PDF is for the distribution $\mathsf{Gamma}(\text{shape}=2,\text{rate}=\frac 1 2).$ See the relevant Wikipedia page (or your textbook) for details. You seek $F_X^{-1}(\frac 1 2) = 3.356694.$
In R statistical software, the inverse CDF (quantile function) is denoted
qgammawith appropriate arguments.I agree with the comment of @StubbornAtom, that the median cannot be negative. The "answer" −1.5361 is simply wrong.
Here is a graph of the PDF, with the location of the median shown by a dotted red line.