# How do I apply a Hadamard gate on a given qubit, in matrix formalism?

$$\frac{1}{\sqrt2}\begin{bmatrix}1 & 1 \\ 1 & -1\end{bmatrix}$$

The matrix for $$|0\rangle$$ is:

$$\begin{bmatrix}1 \\ 0\end{bmatrix}$$

I am unable to understand, how can I apply Hadamard gate on $$|0\rangle$$? The matrix representing $$|0\rangle$$ is of dimension 2 * 1 and the matrix representing Hadamard gate is of dimension 2 * 2 (so the matrix multiplication is not possible)

• Note that: $(2 \times 2)*(2 \times 1) = 2 \times 1$. The dimension of the two number in the inside are the same so it is possible. Remember that matrix multiplication is row by columns. So if the number of elements in the row of $A$ is the same as the number of elements in the column of $B$ then $A*B$ is valid. Oct 5, 2020 at 5:22

Applying quantum gates to quantum states is indeed represented as matrix multiplication. To multiply two matrices, you need only one dimension to match:

$$\frac{1}{\sqrt2}\begin{bmatrix}1 & 1 \\ 1 & -1\end{bmatrix} \begin{bmatrix}1 \\ 0\end{bmatrix} = \frac{1}{\sqrt2}\begin{bmatrix}1 \cdot 1 + 1 \cdot 0 \\ 1 \cdot 1 + (-1) \cdot 0 \end{bmatrix} = \frac{1}{\sqrt2}\begin{bmatrix}1 \\ 1\end{bmatrix}$$

• Thanks a lot. I was confused between H * |0> and |0> * H... Is it correct to always assume that it is <Gate Matrix> * |0> rather than |0> * <Gate Matrix> irrespective of the gate we are talking.... Oct 5, 2020 at 6:02
• Yes, the state is always a column vector, and the gate matrix is applied from the left of the vector Oct 5, 2020 at 6:10

|0> is actually a vector, not a matrix. Applying the Hadamard gate (shortly, H) to |0> means computing a matrix vector multiplication:

$$H|0\rangle = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1\\ 1 & -1 \end{pmatrix} \begin{pmatrix} 1 \\ 0 \end{pmatrix} = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 1 \end{pmatrix} = \frac{|0\rangle + |1\rangle}{\sqrt{2}}$$

• Thanks a lot. I was confused between H * |0> and |0> * H... Is it correct to always assume that it is <Gate Matrix> * |0> rather than |0> * <Gate Matrix> irrespective of the gate we are talking.... Oct 5, 2020 at 6:03

Here's a link to a great matrix multiplier tool:

https://matrixcalc.org/en/