I have some matrix lie algebra $\mathfrak{g}$ and I want to compute the matrix of the adjoint action of $x\in\mathfrak{g}$, $\mathrm{ad}_x:\mathfrak{g}\rightarrow\mathfrak{g}$ given by $y\mapsto[x,y]$. How can I proceed?
I have been told that it should be $\mathrm{ad}_x = x\otimes\mathrm{id} - \mathrm{id}\otimes x$, so I tried to compute it by fixing a basis of $\mathfrak{g}$, computing the tensor of the matrices $x$ and $\mathrm{id}$ and multiplying by the vector representation of some $y\in\mathfrak{g}$. This works fine until I use the canonical basis
$$e_1 = \left(\begin{array}{cc}1 & 0\\0 & 0\end{array}\right),\ \ e_2 = \left(\begin{array}{cc}0 & 1\\0 & 0\end{array}\right),\ \ e_3 = \left(\begin{array}{cc}0 & 0\\1 & 0\end{array}\right),\ \ e_4 = \left(\begin{array}{cc}0 & 0\\0 & 1\end{array}\right)$$
but when I try with a different basis it doesn't work anymore.
You find the matrix of the adjoint action the same way you find the matrix of any linear operator. Choose a basis $\{v_1,\dots,v_n\}$ of $\mathfrak{g}$ (I'm assuming your Lie algebra is finite-dimensional here). Now apply your operator to each basis element. That is, compute $[x,v_j]$ for $j=1,\dots,n$, and express it as a linear combination of your basis elements: $[x,v_j] = \sum_i a_{ij} v_i$. Then the matrix of $\mathrm{ad}_x$ in the basis $\{v_1,\dots,v_n\}$ is the matrix $(a_{ij})$.
Let's compute a specific example. Take the Lie algebra $\mathfrak{sl}_2(\mathbb{C})$, with basis $$ e = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix}, \quad f = \begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix}, \quad h = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}. $$ Let's say we want to compute the matrix of $\operatorname{ad}_e$ in this basis. We have $$ \operatorname{ad}_e(e) = [e,e] = 0,\quad \operatorname{ad}_e(f) = [e,f] = h,\quad \operatorname{ad}_e(h) = [e,h] = -2e. $$ Thus, the matrix of $\operatorname{ad}_e$ in the basis $e,f,h$ is $$ \begin{pmatrix} 0 & 0 & -2 \\ 0 & 0 & 0 \\ 0 & 1 & 0 \end{pmatrix}. $$