# How to write the matrices for Hadamard gates acting on differen qubits?

Can anyone explain the process required to make a Hadamard gate that acts on 1st, 2nd and 3rd qbits?

For Hgates acting on the first qubit i realise the matrix is $H=\begin{pmatrix} 1&1\\1&-1\end{pmatrix}$, but I am unsure how to formulate such a gate. As to acting on the second qubit I have read this web page 1 but I am not really sure if it is correct, because it is just a 4x4 matrix without any zeroes. I found this $\begin{pmatrix} 1 & 1 \\-1 & 1 \end{pmatrix}$ on another website which will obviously have zeroes when it is multiplied by $I$. Simply can anyone explain how Hadarmd gates can be formulated and built to n qubits?

• The web page talks about a Hadamard transform and not a Hadamard gate. To perform a Hadamard transform to an $n$-qubit state, you apply a Hadamard gate to each qubit individually. So the website is correct, but it doesn't directly apply to your question. – Peter Shor Mar 11 '13 at 10:14

For two qubits, the answer is as follows.

The Hadamard gate acting on the second qubit is $$I \otimes H$$:

$$A = \frac{1}{\sqrt{2}} \left( \begin{array}{rrrr} 1&1&0&0\\ 1&-1&0&0\\ 0&0&1&1\\ 0&0&1&-1 \end{array} \right).$$

The Hadamard gate acting on the first qubit is $$H \otimes I$$:

$$B = \frac{1}{\sqrt{2}} \left( \begin{array}{rrrr} 1&0&1&0\\ 0&1&0&1\\ 1&0&-1&0\\ 0&1&0&-1 \end{array} \right).$$

For three qubits, the matrices for the Hadamard gate on the 3rd, 2nd, and 1st qubits are

$$\left(\begin{array}{cc} A & 0 \\ 0 & A \end{array}\right),$$ $$\left(\begin{array}{cc} B & 0 \\ 0 & B \end{array}\right),$$ $$\frac{1}{\sqrt{2}} \left(\begin{array}{rr} I & I \\ I & -I \end{array}\right).$$

Hopefully, you can see the pattern.