Course Home

Linear Algebra for Quantum Computing

An interactive refresher covering the essential linear algebra you need. Work through each section, try the interactive tools, and test yourself with quizzes.

1 Complex Numbers

The number system underlying all of quantum mechanics.

A complex number has the form $z = a + bi$, where $a, b \in \mathbb{R}$ and $i = \sqrt{-1}$. We call $a = \text{Re}(z)$ the real part and $b = \text{Im}(z)$ the imaginary part.

Key Operations
  • Addition: $(a+bi)+(c+di) = (a+c) + (b+d)i$
  • Multiplication: $(a+bi)(c+di) = (ac-bd) + (ad+bc)i$
  • Complex conjugate: $\bar{z} = z^* = a - bi$
  • Modulus: $|z| = \sqrt{a^2+b^2} = \sqrt{z\bar{z}}$
  • Euler form: $z = re^{i\theta}$ where $r=|z|$ and $\theta = \text{arg}(z)$
Why This Matters in Quantum Computing

Quantum states are vectors with complex amplitudes. A qubit state $|\psi\rangle = \alpha|0\rangle + \beta|1\rangle$ has $\alpha, \beta \in \mathbb{C}$ with $|\alpha|^2 + |\beta|^2 = 1$. The phases of these complex numbers encode information that leads to interference — the heart of quantum computation.

Worked Example: Multiplying complex numbers

Problem: Compute $(1+2i)(3-i)$.

Step 1: Expand using FOIL:

$(1)(3) + (1)(-i) + (2i)(3) + (2i)(-i)$

$= 3 - i + 6i - 2i^2$

Step 2: Replace $i^2 = -1$:

$= 3 - i + 6i + 2 = 5 + 5i$

⚙ Interactive: Complex Number Arithmetic
+ i
+ i
Click "Compute" to see results.
🎨 Visualize: The Complex Plane

Click anywhere on the plane to place a complex number. See its real part, imaginary part, modulus, and argument in real time.

Click on the plane to plot a complex number.
✔ Check Your Understanding
What is the modulus of $z = 3 + 4i$?
$7$
$5$
$\sqrt{7}$
$25$
✎ Practice: Compute It Yourself
Compute $(2+i)(1-3i)$. Enter the real and imaginary parts:
Answer: + $i$
✔ Check Your Understanding
What is the complex conjugate of $z = 2 - 3i$?
$-2 + 3i$
$-2 - 3i$
$2 + 3i$
$3 - 2i$

2 Vectors & Dirac Notation

The language of quantum states.

A vector in $\mathbb{C}^n$ is an ordered $n$-tuple of complex numbers. In quantum computing, we primarily work in $\mathbb{C}^2$ (single qubit) and $\mathbb{C}^{2^n}$ ($n$ qubits).

Dirac (Bra-Ket) Notation
NameSymbolMeaning
Ket$|\psi\rangle$Column vector (state)
Bra$\langle\psi|$Conjugate transpose (row vector)
Bracket$\langle\phi|\psi\rangle$Inner product (scalar)
Outer product$|\psi\rangle\langle\phi|$Matrix (operator)

The computational basis for a single qubit is:

$$|0\rangle = \begin{pmatrix} 1 \\ 0 \end{pmatrix}, \qquad |1\rangle = \begin{pmatrix} 0 \\ 1 \end{pmatrix}$$

Any single-qubit state can be written as $|\psi\rangle = \alpha|0\rangle + \beta|1\rangle$ — a superposition.

Important Basis States

$$|+\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix}1\\1\end{pmatrix}, \qquad |-\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix}1\\-1\end{pmatrix}$$
Worked Example: Writing a state in Dirac notation

Problem: Express $\begin{pmatrix} \frac{1}{\sqrt{3}} \\ \frac{i\sqrt{2}}{\sqrt{3}} \end{pmatrix}$ in Dirac notation.

Solution:

$|\psi\rangle = \frac{1}{\sqrt{3}}|0\rangle + \frac{i\sqrt{2}}{\sqrt{3}}|1\rangle$

Verify normalization: $|\alpha|^2 + |\beta|^2 = \frac{1}{3} + \frac{2}{3} = 1$ ✔

Quantum Connection

The normalization constraint $\langle\psi|\psi\rangle = 1$ reflects the fact that measurement probabilities must sum to 1. The probability of measuring outcome $|k\rangle$ is $|\langle k|\psi\rangle|^2$.

✔ Check Your Understanding
What is $\langle 0|$ in row vector form?
$\begin{pmatrix} 1 \\ 0 \end{pmatrix}$
$\begin{pmatrix} 0 & 1 \end{pmatrix}$
$\begin{pmatrix} 1 & 0 \end{pmatrix}$
$\begin{pmatrix} 0 \\ 1 \end{pmatrix}$
✎ Practice: Compute It Yourself
A state $|\psi\rangle = \alpha|0\rangle + \beta|1\rangle$ with $\alpha = \frac{1}{\sqrt{2}}$ must satisfy $|\alpha|^2 + |\beta|^2 = 1$. What is $|\beta|^2$?
$|\beta|^2$ =
✔ Check Your Understanding
If $|\psi\rangle = \frac{1}{2}|0\rangle + \frac{\sqrt{3}}{2}|1\rangle$, what is the probability of measuring $|1\rangle$?
$\frac{1}{2}$
$\frac{\sqrt{3}}{2}$
$\frac{3}{4}$
$\frac{1}{4}$

3 Inner Products

Measuring angles, lengths, and probabilities.

The inner product of two vectors $|u\rangle, |v\rangle \in \mathbb{C}^n$ is:

$$\langle u | v \rangle = \sum_{k=1}^{n} \bar{u}_k v_k$$
Properties
  • Conjugate symmetry: $\langle u|v\rangle = \overline{\langle v|u\rangle}$
  • Linearity in 2nd argument: $\langle u|\alpha v + \beta w\rangle = \alpha\langle u|v\rangle + \beta\langle u|w\rangle$
  • Positive definite: $\langle v|v\rangle \geq 0$, with equality iff $|v\rangle = \mathbf{0}$
  • Norm: $\||v\rangle\| = \sqrt{\langle v|v\rangle}$

Two vectors are orthogonal if $\langle u|v\rangle = 0$. A set of vectors is orthonormal if each pair is orthogonal and each vector has norm 1.

Linear Independence & Bases

A set of vectors $\{|v_1\rangle, \ldots, |v_n\rangle\}$ is linearly independent if no vector can be written as a combination of the others. Formally: $\sum_i c_i |v_i\rangle = 0$ implies all $c_i = 0$.

Why Bases Matter
  • A basis for $\mathbb{C}^n$ is a set of $n$ linearly independent vectors
  • Any vector can be uniquely written as a linear combination of basis vectors
  • An orthonormal basis (ONB) makes computations easy: coefficients are just inner products $c_k = \langle e_k|\psi\rangle$
Quantum Connection

Every measurement corresponds to choosing an orthonormal basis. The computational basis $\{|0\rangle, |1\rangle\}$ is orthonormal ($\langle 0|1\rangle = 0$, $\langle 0|0\rangle = \langle 1|1\rangle = 1$), and the X-basis $\{|+\rangle, |-\rangle\}$ is another. Changing your measurement basis is equivalent to changing which question you ask the qubit! The inner product $\langle\phi|\psi\rangle$ gives the transition amplitude from $|\psi\rangle$ to $|\phi\rangle$, and $|\langle\phi|\psi\rangle|^2$ is the probability of finding the system in state $|\phi\rangle$.

Worked Example: Inner product computation

Problem: Compute $\langle u|v\rangle$ where $|u\rangle = \begin{pmatrix} 1 \\ i \end{pmatrix}$ and $|v\rangle = \begin{pmatrix} 2 \\ 1+i \end{pmatrix}$.

Step 1: Form $\langle u| = \begin{pmatrix} \bar{1} & \overline{i} \end{pmatrix} = \begin{pmatrix} 1 & -i \end{pmatrix}$

Step 2: Compute: $\langle u|v\rangle = (1)(2) + (-i)(1+i) = 2 + (-i - i^2) = 2 + (-i + 1) = 3 - i$

⚙ Interactive: Inner Product Calculator (2D)
u₁: + i
u₂: + i
v₁: + i
v₂: + i
Click "Compute" to see the inner product.
✎ Practice: Compute It Yourself
Compute $\langle u|v\rangle$ where $|u\rangle = \begin{pmatrix}1\\0\end{pmatrix}$ and $|v\rangle = \begin{pmatrix}3\\4\end{pmatrix}$.
$\langle u|v\rangle$ = + $i$
✔ Check Your Understanding
Are $|+\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix}1\\1\end{pmatrix}$ and $|-\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix}1\\-1\end{pmatrix}$ orthogonal?
Yes — their inner product is 0
No — their inner product is 1
No — their inner product is $\frac{1}{2}$

4 Matrices

Operators that transform quantum states.

A matrix $A \in \mathbb{C}^{m \times n}$ is a rectangular array of complex numbers. Matrices act on vectors via multiplication: $A|v\rangle$ produces a new vector.

Essential Operations
  • Transpose: $(A^T)_{ij} = A_{ji}$ — flip rows and columns
  • Complex conjugate: $(\bar{A})_{ij} = \overline{A_{ij}}$
  • Conjugate transpose (adjoint): $A^\dagger = \overline{A^T}$ — crucial in QC!
  • Matrix product: $(AB)_{ij} = \sum_k A_{ik}B_{kj}$
  • Trace: $\text{tr}(A) = \sum_i A_{ii}$
  • Determinant (2×2): $\det\begin{pmatrix}a&b\\c&d\end{pmatrix} = ad-bc$
Important

Matrix multiplication is not commutative: in general $AB \neq BA$. This is physically significant in quantum mechanics — the order in which you apply gates matters!

The 2×2 Identity and Pauli Matrices

$$I = \begin{pmatrix}1&0\\0&1\end{pmatrix}, \quad X = \begin{pmatrix}0&1\\1&0\end{pmatrix}, \quad Y = \begin{pmatrix}0&-i\\i&0\end{pmatrix}, \quad Z = \begin{pmatrix}1&0\\0&-1\end{pmatrix}$$

These form a basis for all 2×2 matrices and correspond to fundamental single-qubit gates.

Worked Example: Applying a gate to a qubit

Problem: Apply the Hadamard gate $H = \frac{1}{\sqrt{2}}\begin{pmatrix}1&1\\1&-1\end{pmatrix}$ to $|0\rangle$.

Solution:

$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} = |+\rangle$

The Hadamard gate creates an equal superposition from a basis state!

⚙ Interactive: 2×2 Matrix × Vector

Enter a 2×2 matrix and a 2D vector (real numbers). Click Compute to see the result.

Click "Compute" to see the result.
🎨 Visualize: Matrix as a Transformation

See how a 2×2 matrix transforms vectors. The blue vector is the input; the yellow vector is the output. Click on the canvas to change the input vector, or pick a gate preset.

Gate: I (Identity) — Click canvas or pick a gate.
✔ Check Your Understanding
What is the effect of the Pauli $X$ gate on $|0\rangle$?
$|0\rangle$ (no change)
$|1\rangle$
$|+\rangle$
$-|0\rangle$
✔ Check Your Understanding
For $A = \begin{pmatrix}1&2i\\-2i&3\end{pmatrix}$, what is $A^\dagger$?
$\begin{pmatrix}1&2i\\-2i&3\end{pmatrix}$
$\begin{pmatrix}1&-2i\\2i&3\end{pmatrix}$
$\begin{pmatrix}1&2i\\2i&3\end{pmatrix}$

5 Eigenvalues & Eigenvectors

The states that survive a transformation (up to scaling).

A non-zero vector $|v\rangle$ is an eigenvector of matrix $A$ with eigenvalue $\lambda$ if:

$$A|v\rangle = \lambda|v\rangle$$

The matrix scales $|v\rangle$ without changing its direction.

Finding Eigenvalues (2×2)

Solve the characteristic equation:

$$\det(A - \lambda I) = 0$$

For $A = \begin{pmatrix}a&b\\c&d\end{pmatrix}$, this gives:

$$\lambda^2 - (a+d)\lambda + (ad-bc) = 0$$

Then find eigenvectors by solving $(A-\lambda I)|v\rangle = 0$ for each $\lambda$.

Quantum Connection

Observable quantities in quantum mechanics correspond to Hermitian matrices, and their eigenvalues are the possible measurement outcomes. After measurement, the system collapses to the corresponding eigenvector. For example, the eigenvalues of $Z$ are $+1$ and $-1$, with eigenvectors $|0\rangle$ and $|1\rangle$.

Worked Example: Eigenvalues of the Pauli Z matrix

Problem: Find the eigenvalues and eigenvectors of $Z = \begin{pmatrix}1&0\\0&-1\end{pmatrix}$.

Step 1 — Characteristic equation:

$\det(Z - \lambda I) = (1-\lambda)(-1-\lambda) = 0$

$\Rightarrow \lambda_1 = 1, \quad \lambda_2 = -1$

Step 2 — Eigenvectors:

For $\lambda_1=1$: $(Z-I)|v\rangle=0 \Rightarrow \begin{pmatrix}0&0\\0&-2\end{pmatrix}\begin{pmatrix}a\\b\end{pmatrix}=0 \Rightarrow b=0 \Rightarrow |v_1\rangle = |0\rangle$

For $\lambda_2=-1$: $(Z+I)|v\rangle=0 \Rightarrow \begin{pmatrix}2&0\\0&0\end{pmatrix}\begin{pmatrix}a\\b\end{pmatrix}=0 \Rightarrow a=0 \Rightarrow |v_2\rangle = |1\rangle$

⚙ Interactive: 2×2 Eigenvalue Calculator

Enter a real 2×2 matrix to find its eigenvalues and eigenvectors.

Presets:
Click "Find Eigenvalues" to compute.
✎ Practice: Compute It Yourself
Find the eigenvalues of $A = \begin{pmatrix}3&0\\0&7\end{pmatrix}$. (Hint: it's diagonal!)
$\lambda_1$ = $\lambda_2$ =
✔ Check Your Understanding
What are the eigenvalues of the Pauli $X = \begin{pmatrix}0&1\\1&0\end{pmatrix}$?
$0$ and $1$
$1$ and $-1$
$i$ and $-i$
$1$ and $1$

6 Tensor Products

Combining quantum systems.

The tensor product (or Kronecker product) $\otimes$ is how we build multi-qubit state spaces from single-qubit ones. If $|u\rangle \in \mathbb{C}^m$ and $|v\rangle \in \mathbb{C}^n$, then $|u\rangle \otimes |v\rangle \in \mathbb{C}^{mn}$.

Definition

For vectors:

$$\begin{pmatrix}a_1\\a_2\end{pmatrix} \otimes \begin{pmatrix}b_1\\b_2\end{pmatrix} = \begin{pmatrix}a_1 b_1\\a_1 b_2\\a_2 b_1\\a_2 b_2\end{pmatrix}$$

For matrices, $A \otimes B$ replaces each entry $a_{ij}$ with the block $a_{ij}B$.

Shorthand: $|0\rangle \otimes |1\rangle = |0\rangle|1\rangle = |01\rangle$.

Entanglement

A state that cannot be written as a tensor product of individual qubit states is called entangled. The most famous example:

$$|\Phi^+\rangle = \frac{1}{\sqrt{2}}(|00\rangle + |11\rangle)$$

You cannot find $|a\rangle, |b\rangle$ such that $|a\rangle \otimes |b\rangle = |\Phi^+\rangle$. This is a uniquely quantum phenomenon!

Worked Example: Tensor product of two qubits

Problem: Compute $|+\rangle \otimes |0\rangle$.

Solution:

$|+\rangle \otimes |0\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix}1\\1\end{pmatrix} \otimes \begin{pmatrix}1\\0\end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix}1 \cdot 1\\1 \cdot 0\\1 \cdot 1\\1 \cdot 0\end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix}1\\0\\1\\0\end{pmatrix}$

In Dirac notation: $\frac{1}{\sqrt{2}}(|00\rangle + |10\rangle)$.

⚙ Interactive: Tensor Product Calculator

Compute |u⟩ ⊗ |v⟩ for two 2D real vectors.

Click "Compute" to see the tensor product.
✎ Practice: Compute It Yourself
Compute $|0\rangle \otimes |1\rangle = \begin{pmatrix}1\\0\end{pmatrix} \otimes \begin{pmatrix}0\\1\end{pmatrix}$. Enter the four components of the result vector:
Result: ( , , , )ᵀ
✔ Check Your Understanding
What is the dimension of the state space for a 3-qubit system?
3
6
8
9

7 Special Matrices

The matrices with physical meaning.

Key Types
TypeConditionQuantum Role
Hermitian$A = A^\dagger$Observables (measurements)
Unitary$UU^\dagger = U^\dagger U = I$Quantum gates
Normal$AA^\dagger = A^\dagger A$Diagonalizable
Projection$P^2 = P = P^\dagger$Measurement projectors

Hermitian Matrices

A matrix $A$ is Hermitian if $A = A^\dagger$. Key properties:

  • All eigenvalues are real
  • Eigenvectors for distinct eigenvalues are orthogonal
  • Can always be diagonalized: $A = \sum_i \lambda_i |v_i\rangle\langle v_i|$ (spectral decomposition)

Unitary Matrices

A matrix $U$ is unitary if $UU^\dagger = I$. Key properties:

  • Preserves inner products: $\langle U\phi|U\psi\rangle = \langle\phi|\psi\rangle$
  • Preserves norms: $\|U|v\rangle\| = \||v\rangle\|$
  • All eigenvalues have $|\lambda| = 1$ (lie on the unit circle)
Quantum Connection

All quantum gates are unitary — this guarantees that valid quantum states remain valid after a gate is applied ($|\alpha|^2+|\beta|^2$ stays 1). Quantum evolution is reversible: applying $U^\dagger$ undoes $U$.

Worked Example: Verifying unitarity of the Hadamard gate

Problem: Verify that $H = \frac{1}{\sqrt{2}}\begin{pmatrix}1&1\\1&-1\end{pmatrix}$ is unitary.

Step 1: Since $H$ is real and symmetric, $H^\dagger = H^T = H$.

Step 2: Compute $HH^\dagger = HH$:

$HH = \frac{1}{2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}\begin{pmatrix}1&1\\1&-1\end{pmatrix} = \frac{1}{2}\begin{pmatrix}2&0\\0&2\end{pmatrix} = \begin{pmatrix}1&0\\0&1\end{pmatrix} = I$ ✔

Therefore $H$ is unitary (and also Hermitian since $H = H^\dagger$).

⚙ Interactive: Matrix Property Checker

Enter a real 2×2 matrix to check if it is unitary and/or Hermitian (symmetric for real matrices).

Click "Check" to verify.
✎ Practice: Compute It Yourself
The Pauli $Z$ matrix has spectral decomposition $Z = (+1)|0\rangle\langle 0| + (-1)|1\rangle\langle 1|$. What are the eigenvalues of $-Z$?
$\lambda_1$ = $\lambda_2$ =
✔ Check Your Understanding
Which of the following is true about unitary matrices?
All eigenvalues are real
All eigenvalues have modulus 1
The determinant is always 1
They are always symmetric

8 Putting It All Together

A complete quantum computing example using everything you've learned.

Let's trace through a simple quantum circuit that demonstrates superposition and measurement.

Full Example: Prepare, Evolve, Measure

Step 1 — Initialize: Start with $|0\rangle = \begin{pmatrix}1\\0\end{pmatrix}$

Step 2 — Apply Hadamard:

$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} = |+\rangle$

Step 3 — Apply Phase gate: $S = \begin{pmatrix}1&0\\0&i\end{pmatrix}$

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

Step 4 — Measure in Z-basis:

$P(|0\rangle) = \left|\frac{1}{\sqrt{2}}\right|^2 = \frac{1}{2}, \qquad P(|1\rangle) = \left|\frac{i}{\sqrt{2}}\right|^2 = \frac{1}{2}$

Equal probabilities — the phase $i$ doesn't affect Z-measurement probabilities!

⚙ Interactive: Step-Through Circuit Simulator

Step through a quantum circuit one gate at a time. Watch how the state vector transforms at each step.

Linear Algebra Checklist for Quantum Computing

You're ready to dive into quantum computing if you can:

  • Multiply complex numbers and find conjugates/moduli
  • Perform matrix-vector multiplication
  • Compute inner products and check orthogonality
  • Find eigenvalues and eigenvectors of 2×2 matrices
  • Compute tensor products of small vectors/matrices
  • Verify whether a matrix is unitary or Hermitian
  • Read and write in Dirac bra-ket notation
✔ Check Your Understanding
Apply the circuit $Z \cdot H$ to $|0\rangle$. What state do you get?
$|+\rangle$
$|-\rangle$
$|0\rangle$
$|1\rangle$
✔ Check Your Understanding
Which of these 2-qubit states is entangled?
$|00\rangle$
$\frac{1}{\sqrt{2}}(|00\rangle + |01\rangle)$
$\frac{1}{\sqrt{2}}(|00\rangle + |11\rangle)$
$|+\rangle \otimes |0\rangle$
✔ Check Your Understanding
If $U$ is unitary and $|\psi\rangle$ is a valid quantum state, is $U|\psi\rangle$ always a valid quantum state?
Yes — unitary matrices preserve norms
Only if $U$ is also Hermitian
Only for real-valued states
Score: 0 / 0