Question:
Let  \[f(x) =
\begin{cases}
k(x) &\text{if }x>0, \\
-\frac1{2x}&\text{if }x< 0\\
0&\text{if }x=0.
\end{cases}
\]Find the function $k(x)$ such that $f(x)$ is its own inverse function.

Answer:
We want to have that $f(f(x))=x$ for every $x.$ If $x=0$ then $f(f(0))=f(0)=0,$ so we are fine.

Since $f$ applied to any negative number returns a positive number, and we can get all positive numbers this way, applying $f$ to any positive number must give a negative number. Therefore $k(x)<0$ for any $x>0.$

If $x>0$ and $f$ is its own inverse then \[x=f(f(x))=f(k(x))=-\frac1{2k(x)},\]where in the last step we used that $k(x)<0.$

Solving this for $k$ gives  \[k(x)=\boxed{-\frac1{2x}}.\]