2
$\begingroup$

Hadamard gate matrix is:

$$\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)

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – KAJ226
    Oct 5, 2020 at 5:22

3 Answers 3

5
$\begingroup$

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}$$

$\endgroup$
2
  • $\begingroup$ 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.... $\endgroup$
    – Kumar
    Oct 5, 2020 at 6:02
  • 1
    $\begingroup$ Yes, the state is always a column vector, and the gate matrix is applied from the left of the vector $\endgroup$ Oct 5, 2020 at 6:10
4
$\begingroup$

|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}}$

$\endgroup$
1
  • $\begingroup$ 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.... $\endgroup$
    – Kumar
    Oct 5, 2020 at 6:03
0
$\begingroup$

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

https://matrixcalc.org/en/

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.