Find the domain and range of a rational function $f(x)=\frac{3x-1}{x+2}$ and its inverse This is a homework question from a precalculus class that I'm a TA for.

Let $f$ be the function given by 
  $$ \tag{$\star$}
f(x) = \frac{3x-1}{x+2}
\,.
$$
  Calculate $f^{-1}(x)$. What are the domains and ranges of $f$ and $f^{-1}$? What do you notice about this?

I wanted to write up a thorough solution to this exercise for my class, and figured I'd post it online to help anyone else who may wander across it.
 A: If you make a square of numbers indicating the four coefficients used here, you get
$$
\left(
\begin{array}{rr}
3 & -1 \\
1 & 2
\end{array}
\right)
$$
If you then interchange the two numbers on the "main diagonal," meaning the upper left corner to the lower right corner, then negate the other two numbers (off the main diagonal) you get
$$
\left(
\begin{array}{rr}
2 & 1 \\
-1 & 3
\end{array}
\right)
$$
Alright, you began with function 
$$ \frac{3x-1}{1x+2}. $$
The inverse function comes from the new square of numbers,
$$ \frac{2x+1}{-1x+3}. $$
This works EVERY TIME.
A: Since $f$ is a rational function, it's defined for all real numbers except where the denominator is equal to zero, so the domain of $f$ is $\mathbb{R}\setminus \{-2\}$. Now the range of $f$ is all real numbers $y$ such that there exists some input $x$ where $f(x) = y$. So to find all such $y$, we may simply take $f(x)$ equal to some arbitrary output $y$ and rearrange the rational expression ($\star$) so find for which $y$ there exists such an $x$:
$$
\tag{$\star\star$}
\begin{align}
f(x) &= y
\\[1em]\implies\qquad
\frac{3x-1}{x+2} &= y
\\[1em]\implies\qquad
x &= \frac{2y+1}{-y+3}
\end{align}
$$
We see that such an $x$ exists for all outputs except $y=3$, where the denominator of the rational expression for $x$ is zero. So the range of $f$ is $\mathbb{R}\setminus\{3\}$.
Now thinking about $f^{-1}$, notice this: if $f(x) = y$, and since $f^{-1}$ is defined to be the function such that $f^{-1}(f(x)) = x$, we get that 
$$
\begin{align}
&\quad f(x) = y 
\\[1em]\quad\implies&\quad 
f^{-1}(f(x)) = f^{-1}(y)
\\[1em]\quad\implies&\quad 
x = f^{-1}(y)
\\[1em]\quad\implies&\quad 
\frac{2y+1}{-y+3} = f^{-1}(y)
\,.
\end{align}
$$
This is an expression for $f^{-1}$! Now if were to insist that the input to a function be named $x$, we could change all the $y$s in that expression to $x$s (they are just names for variables after all, where we usually let $x$ be "inputs" and $y$ be "outputs") and get an honest expression for $f^{-1}(x)$ as 
$$
\frac{2x+1}{-x+3} = f^{-1}(x)
\,.
$$ 
From this we see that the domain of $f^{-1}$ must be $\mathbb{R}\setminus\{3\}$. Now to find the range of $f^{-1}$ we'd do the same procedure we did before in  ($\star\star$). But this would just be doing the algebraic steps in ($\star\star$) in reverse order, and we come back to an expression for the outputs of $f^{-1}$ that just looks like the original function $f$. So the range of $f^{-1}$ will be all real numbers except for $-2$. So in this example, the range of $f$ is the domain of $f^{-1}$, and that the domain of $f$ is the range of $f^{-1}$. 
