Matrix representation of quantum gates I was studying about various quantum gates like Hadamard gate and C-NOT gate. In the Wikipedia article the matrix representation of the gates are given without any derivation. Is there a way to derive the matrix representation of quantum gates?
 A: Sure. Pick a convenient basis of your space of states, where a convenient one is one where you know how the gate acts on it and the action is preferably simple. A matrix is a particular representation of a linear map (the gate). Apply that the $i$-th column of a matrix is simply the image under that map of the $i$-th basis vector expressed in that basis.
A: Suppose we want to write the CNOT gate as a matrix operating on the state space of two qubits. If CNOT were a binary gate, it would act like this:
$$ \begin{aligned}
\mathrm{CNOT}(0, 0) &= (0, 0) \\
\mathrm{CNOT}(0, 1) &= (0, 1) \\
\mathrm{CNOT}(1, 0) &= (1, 1) \\
\mathrm{CNOT}(1, 1) &= (1, 0)
\end{aligned} $$
Here the first bit is the control bit, and the second bit is the one which NOT is applied to if the first bit is 1. The state space of 2 qubits has basis $|00\rangle, |01\rangle, |10\rangle, |11\rangle$, and we want CNOT to be some linear operator $C$ on this state space. From the above definition we must have $C$ acting on our basis elements by:
$$\begin{aligned}
C |00\rangle &= |00\rangle \\
C |01\rangle &= |01\rangle \\
C |10\rangle &= |11\rangle \\
C |11\rangle &= |10\rangle
\end{aligned}$$
Hence we can see that if we were to write $C$ in the ordered basis $B = (|00\rangle, |01\rangle, |10\rangle, |11\rangle)$ we would get the matrix
$$ [C]_B = \begin{pmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 0 & 1 \\
0 & 0 & 1 & 0
\end{pmatrix} $$
