Answer
$\begin{bmatrix}1 &-\frac{1}{x}\\-\frac{1}{x} &\frac{2}{x^2} \end{bmatrix} $
no inverse if $x=0$
Work Step by Step
Step 1. Write the matrix together with an identify as:
$\begin{array}( \\A|I= \\ \\ \end{array}
\begin{bmatrix} 2 & x &| &1 &0\\x & x^2 &| &0 &1 \end{bmatrix} \begin{array}( \\2R_2-xR_1\to R_2 \end{array}$
Step 2. Use row operations to transform the left half into a reduced row-echelon:
$\begin{bmatrix} 2 & x &| &1 &0\\0 & x^2 &| &-x &2 \end{bmatrix} \begin{array}( xR_1-R_2\to R_1\\ \\ \end{array}$
$\begin{bmatrix} 2x & 0 &| &2x &-2\\0 & x^2 &| &-x &2 \end{bmatrix} \begin{array}( R_1/(2x)\to R_1\\R_2/x^2\to R_2 \\ \end{array}$
$\begin{bmatrix} 1 & 0 &| &1 &-\frac{1}{x}\\0 & 1 &| &-\frac{1}{x} &\frac{2}{x^2} \end{bmatrix} $
Step 3. The inverse of the original matrix is:
$\begin{bmatrix}1 &-\frac{1}{x}\\-\frac{1}{x} &\frac{2}{x^2} \end{bmatrix} $
and the matrix does not have an inverse if $x=0$