Vectors¶
Objective¶
Get familiar with vectors and basic vector operations.
Vector Notation¶
In software development, we use arrays all the time. An array is simply a fixedlength collection of elements that have the same type, most often represented as one contiguous chunk of memory. Arrays are usually written with square brackets, like this array of ints:
int[] array = new int[4];
The notation varies between languages, but this syntax should look pretty familiar.
A vector, in the linear algebra sense, is like an array of numbers. The numbers aren't integers, or floats, or doubles, they're just… numbers in the purest abstract sense. They can be real, imaginary, or complex. Like arrays, they're also written with square brackets. Unlike arrays, vectors have one extra property: they have a direction. More specifically, they can either be horizontal (called a row vector) or vertical (called a column vector). The standard notation for vectors looks like this:
Each of these vectors has length 4, because they have 4 elements. When writing vectors, the kind of number you use doesn't matter (but generally, you want to represent them as exactly as you can instead of approximating). We will be using column vectors about 99% of the time in our quantum software work. We won't really need row vectors.
For convenience, in your code comments, you can usually just represent vectors in standard array notation. For example, you could write:
// This vector will be [0, 2, 3.14159, √5/28]
Everyone will assume you're talking about a column vector (in this case, the same as the one in the example above) unless you specifically say that it's a row vector.
Magnitude and Unit Vectors¶
The magnitude of a vector is like the magnitude of a complex number: it's the square root of the sum of all of the terms' magnitudes squared. Also like complex numbers, vector magnitude is represented with vertical bars:
For real numbers, the magnitude of a number is just the absolute value of the number itself. For complex numbers, recall from the previous page on complex numbers that the magnitude is the square root of the sum of the real and imaginary coefficients squared (go back and look at it if you need to see the formula).
If the magnitude of a vector is 1, then it is called a unit vector. This will be important, because quantum computing exclusively uses unit vectors.
Math Properties¶
Addition¶
To add two vectors together, they have to be the same length and the same type (column and column, or row and row). Just add each element to its partner:
Scalar Multiplication¶
To multiply a vector by a constant factor, just multiply each element by it.
Additional Materials¶

Khan Academy lesson on vectors in the context of linear algebra
 All the videos and exercises are relevant except parametric representations of lines.
Knowledge Check¶
Q1¶
Q2¶
Q3¶
Q4¶
What is the speed of an object whose velocity vector is given as \(\begin{bmatrix} v_x \\ v_y \end{bmatrix} = \begin{bmatrix} 12 \\ 5 \end{bmatrix}\)
Q5¶
Q6¶
Which of the following is a unit vector? (Select all that apply.)
A: \(\begin{bmatrix} 1 \\ 0 \end{bmatrix}\)
B: \(\begin{bmatrix} 1 \\ 1 \end{bmatrix}\)
C: \(\begin{bmatrix} \frac{\sqrt{3}}{2} \\ \frac{1}{2} \end{bmatrix}\)
D: \(\begin{bmatrix} 0 \\ 0 \\ i \end{bmatrix}\)
E: \(\begin{bmatrix} \frac{1}{\sqrt{3}} \\ \frac{1}{\sqrt{3}} \\ \frac{1}{\sqrt{3}} \end{bmatrix}\)
Q7¶
What is the unit vector that points in the same direction as \(\begin{bmatrix} 4 \\ 3 \end{bmatrix}\)?