Skip to content
Quantum ComputingAN INTERACTIVE OPEN TEXTBOOK
charithj.com.au

Vectors, matrices and linear algebra

Quantum states are vectors. Gates are matrices. A small calculation connects the two.

16 min readDr. Charith Jayasekara↓ Chapter PDF
By the end, you’ll be able to
  • Multiply a two-by-two matrix by a state vector.
  • Explain norm preservation for an ideal quantum gate.

We represent the basis states with two simple columns:

∣0⟩=(10),∣1⟩=(01).\lvert0\rangle=\begin{pmatrix}1\\0\end{pmatrix},\qquad \lvert1\rangle=\begin{pmatrix}0\\1\end{pmatrix}.

A general pure qubit has column (α,β)T(\alpha,\beta)^T. Its squared norm is ∣α∣2+∣β∣2=1|\alpha|^2+|\beta|^2=1.

The X gate exchanges the two amplitudes:

X=(0110),X(αβ)=(βα).X=\begin{pmatrix}0&1\\1&0\end{pmatrix},\qquad X\begin{pmatrix}\alpha\\\beta\end{pmatrix}=\begin{pmatrix}\beta\\\alpha\end{pmatrix}.

To multiply a matrix by a column, take each row’s dot product with the column. For the first row above, 0α+1β=β0\alpha+1\beta=\beta.

The Hadamard gate is

H=12(111−1).H=\frac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}.

Applying it to ∣0⟩\lvert0\rangle gives (1,1)T/2(1,1)^T/\sqrt2. Applying it again gives (1,0)T(1,0)^T. The cancellation in the second component is interference in matrix form.

An ideal closed-system gate UU satisfies U†U=IU^\dagger U=I, where the dagger means conjugate transpose. This property preserves inner products and norms, so valid states remain normalised. It also means U−1=U†U^{-1}=U^\dagger.

Measurement and noisy evolution need more general descriptions; do not assume every physical operation is a unitary gate on the subsystem you observe.

Calculate H∣1⟩H\lvert1\rangle. You should obtain (1,−1)T/2(1,-1)^T/\sqrt2. Then verify X2=IX^2=I and H2=IH^2=I directly. Use the gate playground to compare the numerical outputs with your calculation.

WORKED DIAGRAM · F04The two columns of the Hadamard matrix
The two columns of the Hadamard matrixSigned REAL amplitudes for H|0⟩ and H|1⟩. A negative bar is a negative amplitude, never a negative probability. Both states give 50/50 Z counts.H|0⟩|0⟩0.707|1⟩0.7070 · signed scale −1 to +1H|1⟩|0⟩0.707|1⟩-0.7070 · signed scale −1 to +1
Signed REAL amplitudes for H|0⟩ and H|1⟩. A negative bar is a negative amplitude, never a negative probability. Both states give 50/50 Z counts.

The first column of a gate matrix is its output on the zero basis state. The second column is its output on the one basis state. That observation is a quick way to interpret H: its columns are the plus and minus states. Their probabilities agree, but the second column contains a negative amplitude. A histogram alone therefore cannot verify the matrix action. You need either the statevector in a simulation or another operation that turns the phase difference into a measurable one.

For a general input, multiply each matrix column by the corresponding input amplitude and add the resulting columns. This is the same operation as taking row-by-column products. The column view highlights linearity: knowing what the gate does to each basis vector fixes what it does to any superposition. You cannot independently assign a different rule when the input happens to be unknown.

Insert the column for the one state into the matrix expression. The first output component is one divided by the square root of two. The second is negative one divided by the square root of two:

H(01)=12(1−1).H\begin{pmatrix}0\\1\end{pmatrix} =\frac1{\sqrt2}\begin{pmatrix}1\\-1\end{pmatrix}.

Both squared magnitudes are one half. The negative sign is a relative phase, because only one component changed sign compared with the plus state. Apply H again. The new first component is proportional to one plus negative one and cancels. The new second component is proportional to one minus negative one and reinforces. The output is the one basis state, as required by the identity that two H gates undo each other.

Repeat the calculation on the zero input. After one H both components are positive, so the second H restores zero instead. These two tests distinguish a correct H implementation from a function that simply returns equal probabilities for every input. Equal probabilities are only one consequence of the matrix; they are not a complete specification of the gate.

Take a normalised input with amplitudes one over the square root of two and i over the square root of two. Applying H produces amplitudes one half plus i over two and one half minus i over two. Each has squared magnitude one half. The total is one, but the two output phases differ. This example checks the imaginary arithmetic as well as the real columns.

Norm preservation is necessary for a closed-system gate, but testing a single input is insufficient to prove it. A broken matrix might preserve the zero state while stretching other directions. Unitarity checks all directions at once through the conjugate-transpose identity. Equivalently, the columns must have unit norm and be mutually orthogonal. For H, each column has squared norm one, and their inner product is one half minus one half, which is zero.

Matrix multiplication also explains why gate order matters. X exchanges components, while H adds and subtracts them. Applying X then H to zero gives the minus state. Applying H then X gives the plus state. Since these outputs are different, the two sequences are not interchangeable. A circuit diagram and its algebra should identify both the input and the chronological order, not just list gate names.

This instance starts with one qubit and basis-state input one. Add H on q0. Predict both signed amplitudes before revealing the result. The table should show approximately positive 0.707107 for zero and negative 0.707107 for one, with equal probabilities. Add another H, record a new prediction and check that the one outcome becomes certain. The result is recomputed from the original input and the complete displayed circuit.

Now change the input selector to zero while keeping the same two-H circuit. Predict the output again. Then use Undo last gate to compare the one-H output. This sequence separates three concepts: changing the input, editing the circuit and sampling its output. Reset restores the lesson’s one-input preset and clears the gates.

L02 · INTERACTIVE LABRuns on your device

Quantum gate playground

Choose a basis-state input and a one-, two- or three-qubit register. Build gates left to right and inspect their complex statevector after recording a prediction.

Experiment controls
|1⟩ → I
Maximum 20 gates. q0 is the leftmost bit. Editing a circuit recomputes it from the input.

For the chosen input and circuit, predict the nonzero amplitudes, their signs and the measured bitstrings.

Record a prediction to enable the results.

Results are hidden.

Prepare your experiment using the controls. Record a prediction, then reveal the statevector or run the experiment.

Changing the preparation or circuit starts a new prediction.

MODEL · Ideal pure-state vector, complex double precisionORDER · q0 is the leftmost bit
Take it further

Compare H|0⟩ with H|1⟩ using one qubit. Their Z probabilities agree; their amplitude signs do not. Add a second H to distinguish them.

Someone proposes a diagonal matrix with entries one and two as an ideal gate. It leaves the zero state unchanged. Apply it to the plus state and calculate the squared norm. Can normalising the output afterward turn this into the same kind of deterministic linear gate?

Check your reasoning

The output is the column with entries one over the square root of two and two over the square root of two. Its squared norm is five halves, so the matrix is not unitary. Renormalising introduces a factor that depends on the input state and does not restore a deterministic linear unitary transformation. Conditional operations can have nonunitary descriptions, but their success probabilities and measurement records must also be modelled.

PAUSE & THINK

After H acts on |1⟩, what is the amplitude of |1⟩?

Choose your answer

Reference: IBM Quantum — Quantum information.

ONE IDEA FURTHER

Ready for the next step?

Your progress stays in this browser.