Euclidean space — theory with music taste: dot product, Gram matrix, angles, Gram-Schmidt and cross product (and the ± I did not need)

In quiz 3 on the Campus there was a question about how the norm of a vector is defined, and among the options were ±u⃗⋅u⃗\pm\sqrt{\vec u \cdot \vec u} and +u⃗⋅u⃗+\sqrt{\vec u \cdot \vec u}. I ticked the one with ± and got it wrong. A length cannot be negative: the norm is the positive root, always. The ± is for when you look for the two unit vectors of a direction, which is something else, and in this article you will see both so you never mix them up again.

This topic adds to the vector spaces of topic 3 a tool for measuring: the dot product (or inner product). With it you compute lengths, angles and perpendiculars, and orthonormal bases, the orthogonal projection and the cross product appear. The example for the whole article is music taste: what you listen to each week of pop, rock and classical music is a vector, and the angle between two of those vectors says how alike two people are. It is the idea behind many recommender systems, and you will see it in Data Science more often than you think. After the theory you have the guided practice.

In a nutshell: a dot product is a rule that assigns a number to two vectors and satisfies four properties (symmetric, linear and positive definite). A vector space with a dot product is a Euclidean space. With it you define the norm ∥u⃗∥=+u⃗⋅u⃗\lVert \vec u \rVert = +\sqrt{\vec u \cdot \vec u}, the angle cos⁡α=u⃗⋅v⃗∥u⃗∥∥v⃗∥\cos \alpha = \frac{\vec u \cdot \vec v}{\lVert \vec u \rVert \lVert \vec v \rVert} and orthogonality (u⃗⋅v⃗=0\vec u \cdot \vec v = 0). In a basis, the product is written XtGYX^t G Y, with GG the Gram matrix.

Before you start. For this topic all you need is what you saw in topic 3: what a vector of Rn \mathbb{R}^n is, what a basis is and how to write the coordinates of a vector in it (and the change-of-basis matrix, for congruent matrices). As for matrices, multiplying a row by a matrix by a column. Nothing else. The topic has three big ideas, in this order: a rule to measure how much two vectors share (the dot product, and its Gram matrix); what comes out of it, lengths, angles and perpendiculars (norm, cosine, orthogonality); and how to make use of perpendiculars (orthonormal bases, Gram-Schmidt, projection), with the cross product and the scalar triple product at the end, which only exist in R3 \mathbb{R}^3 . If you get lost at any point, go back to music taste: the whole topic can be told with it.

Your taste is a vector

I write down how many hours a week each person in my group listens to pop, rock and classical:

PersonPopRockClassicalVector
Sergio212s⃗=(2,1,2)\vec s = (2, 1, 2)
Laura221l⃗=(2,2,1)\vec l = (2, 2, 1)
Pablo004p⃗=(0,0,4)\vec p = (0, 0, 4)
Ana340a⃗=(3,4,0)\vec a = (3, 4, 0)

They are vectors of R3\mathbb{R}^3, like the colours of topic 3, and they can be added and multiplied by numbers. But now the question is different: who am I most like? To answer it you need to measure, and a vector space on its own measures nothing: it does not know what a length or an angle is. That is what the dot product adds.

Music taste as vectorsAxes pop, rock and classical in perspective with four arrows: Sergio (2,1,2), Laura (2,2,1), Pablo (0,0,4) only classical and Ana (3,4,0) on the pop-rock floor. Beside: the product of Sergio and Laura is 8, Ana and Pablo is 0, and the norms of Sergio and Ana are 3 and 5.poprockclass.Sergio (2,1,2)Laura (2,2,1)Pablo (0,0,4)Ana (3,4,0)hours per weeks · l = 8a · p = 0‖s‖ = 3‖a‖ = 5Ana and Pablo: nothing in common
Each person is a vector; the dot product says how much they share.

The dot product

Before the definition, let’s invent the rule in our heads. The question is: how would you measure, with a single number, how much Sergio and Laura share?

Genre by genre. If both of them listen to pop, that pop counts; if one of them listens to none of a genre, that genre should count for nothing. The operation that does exactly that is multiplying: if one of the two numbers of hours is 0, the product is 0. Then you add up the three genres:

GenreSergioLauraProductWhy
Pop224Both listen to quite a lot: it counts a lot
Rock122Laura listens to more, but I only do 1: what is shared is small
Classical212Same as rock, the other way round
Total8You add what they share in each genre

Why not simply add the hours? Because then it would count what only one person listens to: Pablo’s 4 hours of classical would make it look as if he shared something with Ana, who listens to no classical at all. With the product, Ana and Pablo give 0, which is fair.

Now notice four things this rule does without you asking for them. Sharing is mutual: Sergio with Laura gives the same as Laura with Sergio. If Laura listened to twice as much of everything, what is shared would double. If you put the hours of two people together in one list, what that list shares with Sergio is the sum of what each of them shares. And a person always shares something positive with themselves (me with me, 4+1+4=9 4 + 1 + 4 = 9 ), unless they listen to nothing. Those four things, with their official names, are the definition:

A dot product on a real vector space VV is a rule that assigns to each pair of vectors u⃗,v⃗\vec u, \vec v a real number u⃗⋅v⃗\vec u \cdot \vec v and satisfies, for all u⃗,v⃗,w⃗∈V\vec u, \vec v, \vec w \in V and λ∈R\lambda \in \mathbb{R}:

  1. Symmetric: u⃗⋅v⃗=v⃗⋅u⃗\vec u \cdot \vec v = \vec v \cdot \vec u.
  2. Distributive: (u⃗+v⃗)⋅w⃗=u⃗⋅w⃗+v⃗⋅w⃗(\vec u + \vec v) \cdot \vec w = \vec u \cdot \vec w + \vec v \cdot \vec w.
  3. Takes out scalars: (λu⃗)⋅v⃗=λ(u⃗⋅v⃗)(\lambda \vec u) \cdot \vec v = \lambda (\vec u \cdot \vec v).
  4. Positive definite: u⃗⋅u⃗≥0\vec u \cdot \vec u \geq 0, and u⃗⋅u⃗=0\vec u \cdot \vec u = 0 only if u⃗=0⃗\vec u = \vec 0.

In Rn\mathbb{R}^n, the standard dot product multiplies component by component and adds:

(x1,…,xn)⋅(y1,…,yn)=x1y1+x2y2+⋯+xnyn (x_1, \dots, x_n) \cdot (y_1, \dots, y_n) = x_1 y_1 + x_2 y_2 + \dots + x_n y_n

With the tastes: s⃗⋅l⃗=2⋅2+1⋅2+2⋅1=4+2+2=8\vec s \cdot \vec l = 2 \cdot 2 + 1 \cdot 2 + 2 \cdot 1 = 4 + 2 + 2 = 8. The number is large when both listen to a lot of the same. And a⃗⋅p⃗=3⋅0+4⋅0+0⋅4=0\vec a \cdot \vec p = 3 \cdot 0 + 4 \cdot 0 + 0 \cdot 4 = 0: Ana and Pablo do not share a single genre.

A real vector space with a dot product is called a Euclidean vector space. R2\mathbb{R}^2 and R3\mathbb{R}^3 with the standard product are the usual ones, but it is not the only possible product, and that is what makes the exam interesting.

The Gram matrix

If B={e⃗1,…,e⃗n}B = \{\vec e_1, \dots, \vec e_n\} is a basis and you write u⃗\vec u and v⃗\vec v with their coordinates XX and YY in it, properties 2 and 3 turn the product into:

u⃗⋅v⃗=Xt G Y=(x1⋯xn)(g11⋯g1n⋮⋱⋮gn1⋯gnn)(y1⋮yn),gij=e⃗i⋅e⃗j \vec u \cdot \vec v = X^t \, G \, Y = \begin{pmatrix} x_1 & \cdots & x_n \end{pmatrix} \begin{pmatrix} g_{11} & \cdots & g_{1n} \\ \vdots & \ddots & \vdots \\ g_{n1} & \cdots & g_{nn} \end{pmatrix} \begin{pmatrix} y_1 \\ \vdots \\ y_n \end{pmatrix}, \qquad g_{ij} = \vec e_i \cdot \vec e_j

GG is the Gram matrix (or metric matrix) of the product in the basis BB: in position (i,j)(i, j), the product of basis vector ii by basis vector jj. It is symmetric, because e⃗i⋅e⃗j=e⃗j⋅e⃗i\vec e_i \cdot \vec e_j = \vec e_j \cdot \vec e_i. With the standard product and the standard basis, e⃗i⋅e⃗j\vec e_i \cdot \vec e_j is 1 if i=ji = j and 0 otherwise, so G=IG = I and you get back the sum of products.

Look carefully at the shapes: row times matrix times column. A 1×n1 \times n row times an n×nn \times n times an n×1n \times 1 column gives a 1×11 \times 1, a number, which is what a dot product has to give.

The shape of the matrix expressionOn the left, a 1 by 3 row times a 3 by 3 matrix times a 3 by 1 column gives a 1 by 1, a number. On the right, a 3 by 1 column times a 3 by 3 matrix cannot be multiplied. Below, u · v = Xᵗ G Y = Yᵗ G X because G is symmetric.right: row · G · columnXᵗ 1×3G 3×3Y 3×1=1×1a numberwrong: column · G · row3×13×31×3cannot be multiplied×u · v = Xᵗ G Y = Yᵗ G X (G symmetric)
The sizes say it all: what is left outside is 1 × 1.

Writing Y G XtY \, G \, X^t, column times matrix times row. It cannot even be multiplied in that order (n×1n \times 1 by n×nn \times n), and if you swap the factors so that it fits, you get an n×nn \times n matrix, not a number. It is the trap of a multiple-answer question in quiz 3: the two row ⋅\cdot GG ⋅\cdot column options are right (with u⃗\vec u first or with v⃗\vec v first, by symmetry) and none of the others.

Another dot product. Suppose pop and rock are alike and you want them to count “a bit together”. You define

u⃗⋅Gv⃗=XtGYwithG=(210120001) \vec u \cdot_G \vec v = X^t G Y \quad \text{with} \quad G = \begin{pmatrix} 2 & 1 & 0 \\ 1 & 2 & 0 \\ 0 & 0 & 1 \end{pmatrix}

It is symmetric, and it is positive definite (you will check it with Sylvester’s criterion in topic 6; for now, trust it). With this product, s⃗⋅Gl⃗\vec s \cdot_G \vec l:

G l⃗ t=(2⋅2+1⋅2+01⋅2+2⋅2+00+0+1⋅1)=(661),s⃗⋅Gl⃗=(2,1,2)⋅(6,6,1)=12+6+2=20 G \, \vec l^{\,t} = \begin{pmatrix} 2 \cdot 2 + 1 \cdot 2 + 0 \\ 1 \cdot 2 + 2 \cdot 2 + 0 \\ 0 + 0 + 1 \cdot 1 \end{pmatrix} = \begin{pmatrix} 6 \\ 6 \\ 1 \end{pmatrix}, \qquad \vec s \cdot_G \vec l = (2, 1, 2) \cdot (6, 6, 1) = 12 + 6 + 2 = 20

The calculation with G, term by term

Before doing the calculation, read what G G says. Each entry gij g_{ij} says how much it is worth to combine genre i i of one person with genre j j of the other. Here g11=g22=2 g_{11} = g_{22} = 2 : pop with pop and rock with rock count double. g12=g21=1 g_{12} = g_{21} = 1 : my pop with Laura’s rock (and my rock with her pop) also counts for something, even though it is not the same genre. g33=1 g_{33} = 1 : classical, as before. And the zeros: classical does not mix with anything.

XtGY X^t G Y means adding up xi gij yj x_i \, g_{ij} \, y_j over all the entries. The ones with a 0 contribute nothing, so five terms are left:

EntryCalculationContributesWhy
g11 g_{11} 2⋅2⋅2 2 \cdot 2 \cdot 2 8My pop (2) times Laura’s pop (2), with weight 2
g12 g_{12} 2⋅1⋅2 2 \cdot 1 \cdot 2 4My pop (2) times Laura’s rock (2), with weight 1
g21 g_{21} 1⋅1⋅2 1 \cdot 1 \cdot 2 2My rock (1) times Laura’s pop (2), with weight 1
g22 g_{22} 1⋅2⋅2 1 \cdot 2 \cdot 2 4My rock (1) times Laura’s rock (2), with weight 2
g33 g_{33} 2⋅1⋅1 2 \cdot 1 \cdot 1 2My classical (2) times Laura’s (1), with weight 1
Total20The same as with G l⃗ t G \, \vec l^{\,t}

With G=I G = I only the three diagonal entries would be left, with weight 1: 4+2+2=8 4 + 2 + 2 = 8 , the standard product. Doing G G times the column first, as above, is faster in the exam; term by term you see where each number comes from.

Check you’ve got it: with the product G, what is the product of Sergio with Ana, and why does it go up so much compared with the standard one?

It is 31, against 10 with the standard product. Step by step: G a⃗ t=(2⋅3+1⋅4, 1⋅3+2⋅4, 0)=(10,11,0) G \, \vec a^{\,t} = (2 \cdot 3 + 1 \cdot 4,\ 1 \cdot 3 + 2 \cdot 4,\ 0) = (10, 11, 0) , and (2,1,2)⋅(10,11,0)=20+11+0=31 (2, 1, 2) \cdot (10, 11, 0) = 20 + 11 + 0 = 31 . It goes up so much because Ana only listens to pop and rock, which are exactly the genres G G reinforces: they weigh double and they also mix with each other. My classical, on the other hand, contributes nothing, because Ana has a 0 there.

The same pair of vectors, a different number. A dot product is not “the” product: it is a choice of how to measure.

Congruent matrices

If you change basis, the Gram matrix changes. With C=CB′→BC = C_{B' \to B} (the vectors of B′B' as columns, as in topic 3), the one in the new basis is

G′=Ct G C G' = C^t \, G \, C

and GG and G′G' are called congruent matrices: they represent the same dot product in two different bases, and they have the same rank. For example, with the standard product (G=I3G = I_3) and the yellow, cyan and magenta basis from topic 3:

C=(101110011),G′=CtI3 C=CtC=(211121112) C = \begin{pmatrix} 1 & 0 & 1 \\ 1 & 1 & 0 \\ 0 & 1 & 1 \end{pmatrix}, \qquad G' = C^t I_3 \, C = C^t C = \begin{pmatrix} 2 & 1 & 1 \\ 1 & 2 & 1 \\ 1 & 1 & 2 \end{pmatrix}

Each entry is a product of two basis vectors: g11′=(1,1,0)⋅(1,1,0)=2g'_{11} = (1, 1, 0) \cdot (1, 1, 0) = 2, g12′=(1,1,0)⋅(0,1,1)=1g'_{12} = (1, 1, 0) \cdot (0, 1, 1) = 1, and so on.

The norm and unit vectors

Before the formula, in your head: how long is Sergio’s arrow, (2,1,2) (2, 1, 2) ? If it were only pop and rock, (2,1) (2, 1) , it would be the hypotenuse of a triangle with legs 2 and 1: 22+12=5 \sqrt{2^2 + 1^2} = \sqrt5 . With classical, Pythagoras again: that hypotenuse and the height 2 are the legs of another triangle, and you get 5+22=9=3 \sqrt{5 + 2^2} = \sqrt9 = 3 .

Now look at what is inside the root: 22+12+22 2^2 + 1^2 + 2^2 , which is exactly s⃗⋅s⃗ \vec s \cdot \vec s , what Sergio shares with himself. So the length comes out of the dot product without inventing anything new. The root is needed because s⃗⋅s⃗ \vec s \cdot \vec s multiplies hours by hours; the root brings the number back to the scale of hours. And the root is the positive one because it is a length: −3 -3 also satisfies (−3)2=9 (-3)^2 = 9 , but an arrow does not measure −3 -3 . That is the mistake from the quiz at the beginning.

The norm (or modulus, or length) of a vector is

∥u⃗∥=+u⃗⋅u⃗ \lVert \vec u \rVert = +\sqrt{\vec u \cdot \vec u}

with the positive root. It satisfies ∥u⃗∥≥0\lVert \vec u \rVert \geq 0, ∥u⃗∥=0\lVert \vec u \rVert = 0 only if u⃗=0⃗\vec u = \vec 0, and ∥λu⃗∥=∣λ∣ ∥u⃗∥\lVert \lambda \vec u \rVert = \lvert \lambda \rvert \, \lVert \vec u \rVert. With the standard product of Rn\mathbb{R}^n, it is Pythagoras: ∥(x1,…,xn)∥=+x12+⋯+xn2\lVert (x_1, \dots, x_n) \rVert = +\sqrt{x_1^2 + \dots + x_n^2}.

∥s⃗∥=+22+12+22=+9=3,∥a⃗∥=+9+16+0=5 \lVert \vec s \rVert = +\sqrt{2^2 + 1^2 + 2^2} = +\sqrt{9} = 3, \qquad \lVert \vec a \rVert = +\sqrt{9 + 16 + 0} = 5

It measures how much you listen in total (in a “Euclidean” sense), not what you listen to. With the product GG above, the norm of s⃗\vec s is different: s⃗⋅Gs⃗=(2,1,2)⋅(5,4,2)=10+4+4=18\vec s \cdot_G \vec s = (2, 1, 2) \cdot (5, 4, 2) = 10 + 4 + 4 = 18, so ∥s⃗∥G=18=32\lVert \vec s \rVert_G = \sqrt{18} = 3\sqrt2.

A unit vector is one with norm 1. Dividing a vector by its norm gives a unit vector with the same direction, and there are two in each direction, one for each sense:

±u⃗∥u⃗∥⟹±(2,1,2)3=±(23,13,23) \pm \frac{\vec u}{\lVert \vec u \rVert} \qquad \Longrightarrow \qquad \pm \frac{(2, 1, 2)}{3} = \pm \left( \tfrac23, \tfrac13, \tfrac23 \right)

Here there is a ±, and it is the one you must not carry over to the norm. Sergio’s unit vector is his profile: what he listens to, regardless of how much.

Writing ∥u⃗∥=±u⃗⋅u⃗\lVert \vec u \rVert = \pm \sqrt{\vec u \cdot \vec u}. The norm is a length and it is unique and positive. The ± appears when you look for the unit vectors of a direction: ±u⃗/∥u⃗∥\pm \vec u / \lVert \vec u \rVert.

The angle between two vectors

Before the definition, a question: does the dot product tell me who I am most like? Almost. With the friend who listens to twice as much of everything as me, (4,2,4) (4, 2, 4) , the product is 8+2+8=18 8 + 2 + 8 = 18 , more than twice the one with Laura, even though he has exactly my taste. The dot product mixes two things: what you listen to and how much you listen. For likeness we only care about the first.

The way to remove the “how much” is the one from the previous section: divide each vector by its norm and keep its unit vector, its profile. My profile is (23,13,23) (\tfrac23, \tfrac13, \tfrac23) , my friend’s is the same, and their product is 1. Laura’s is (23,23,13) (\tfrac23, \tfrac23, \tfrac13) , and

(23,13,23)⋅(23,23,13)=49+29+29=89 \left( \tfrac23, \tfrac13, \tfrac23 \right) \cdot \left( \tfrac23, \tfrac23, \tfrac13 \right) = \tfrac49 + \tfrac29 + \tfrac29 = \tfrac89

It does not matter whether you divide before or after: since the product takes scalars out, it is the same as s⃗⋅l⃗ \vec s \cdot \vec l divided by ∥s⃗∥ ∥l⃗∥ \lVert \vec s \rVert \, \lVert \vec l \rVert , 83⋅3 \tfrac{8}{3 \cdot 3} . And why is it called a cosine? In the plane, a unit vector at an angle α \alpha from (1,0) (1, 0) is (cos⁡α,sin⁡α) (\cos \alpha, \sin \alpha) , and its product with (1,0) (1, 0) is cos⁡α \cos \alpha . The product of two profiles is the cosine of the angle between them. That, with its name, is the definition:

The angle α\alpha between two non-zero vectors is defined by

cos⁡α=u⃗⋅v⃗∥u⃗∥ ∥v⃗∥,0≤α≤π \cos \alpha = \frac{\vec u \cdot \vec v}{\lVert \vec u \rVert \, \lVert \vec v \rVert}, \qquad 0 \leq \alpha \leq \pi

(The Cauchy-Schwarz inequality, ∣u⃗⋅v⃗∣≤∥u⃗∥∥v⃗∥\lvert \vec u \cdot \vec v \rvert \leq \lVert \vec u \rVert \lVert \vec v \rVert, guarantees the quotient is between −1-1 and 11.) In data science this cosine is called cosine similarity: it compares profiles, not amounts.

cos⁡(s⃗,l⃗)=83⋅3=89≈0.8889⟹α≈27.27∘ \cos(\vec s, \vec l) = \frac{8}{3 \cdot 3} = \frac89 \approx 0.8889 \quad \Longrightarrow \quad \alpha \approx 27.27^\circ
cos⁡(s⃗,p⃗)=2⋅0+1⋅0+2⋅43⋅4=812=23⟹α≈48.19∘ \cos(\vec s, \vec p) = \frac{2 \cdot 0 + 1 \cdot 0 + 2 \cdot 4}{3 \cdot 4} = \frac{8}{12} = \frac23 \quad \Longrightarrow \quad \alpha \approx 48.19^\circ

I am more like Laura than Pablo. And a friend who listened to twice as much of everything as me, (4,2,4)(4, 2, 4), would have cosine 1 with me: the same profile, angle 0.

This is Sergio against the whole group, with the why of each row:

PersonProduct with s⃗ \vec s NormCosineWhy
Laura8389≈0.8889 \tfrac89 \approx 0.8889 Listens to a bit of everything, like me, with more rock
Pablo8423≈0.6667 \tfrac23 \approx 0.6667 Only shares my classical
Ana10523≈0.6667 \tfrac23 \approx 0.6667 Only shares my pop and my rock
Friend (4,2,4) (4, 2, 4) 1861Same profile, twice the hours

Look at Pablo and Ana: both are at about 48.19∘ 48.19^\circ from me, and they have nothing in common with each other. Each of them is like a different part of me.

Comparing dot products instead of cosines. With Ana the product is 10 and with Laura 8, and you would say I am more like Ana. But Ana listens to more hours in total (her norm is 5); once you divide, Laura clearly wins.

And if the dot product is 0, the cosine is 0 without looking at the norms, because the denominator is never 0: that is the next section.

Check you’ve got it: who is Laura more like, Pablo or Ana?

Ana. Step by step: l⃗⋅p⃗=0+0+1⋅4=4 \vec l \cdot \vec p = 0 + 0 + 1 \cdot 4 = 4 and l⃗⋅a⃗=6+8+0=14 \vec l \cdot \vec a = 6 + 8 + 0 = 14 . The norms are 3, 4 and 5, so cos⁡(l⃗,p⃗)=412=13≈0.3333 \cos(\vec l, \vec p) = \tfrac{4}{12} = \tfrac13 \approx 0.3333 (about 70.53∘ 70.53^\circ ) and cos⁡(l⃗,a⃗)=1415≈0.9333 \cos(\vec l, \vec a) = \tfrac{14}{15} \approx 0.9333 (about 21.04∘ 21.04^\circ ). Laura mostly listens to pop and rock, like Ana; with Pablo she only shares one hour of classical.

The angle as a measure of similarityThree pairs of arrows: Sergio and Laura make about 27 degrees, cosine 8/9; Sergio and Pablo, about 48 degrees, cosine 2/3; Ana and Pablo, 90 degrees, cosine 0.27°Sergio and Lauracos = 8/9 ≈ 0.88948°Sergio and Pablocos = 2/3 ≈ 0.66790°Ana and Pablocos = 0
The closer the cosine is to 1, the more alike the profiles are.

With the product GG the angle changes, because the way of measuring changes: ∥l⃗∥G2=(2,2,1)⋅(6,6,1)=25\lVert \vec l \rVert_G^2 = (2, 2, 1) \cdot (6, 6, 1) = 25, so

cos⁡G(s⃗,l⃗)=2032⋅5=432=223≈0.9428 \cos_G(\vec s, \vec l) = \frac{20}{3\sqrt2 \cdot 5} = \frac{4}{3\sqrt2} = \frac{2\sqrt2}{3} \approx 0.9428

If pop and rock “count together”, Laura is even more like me. That is how it appears in the exam: you are given a dot product (in topic 6, from a bilinear form) and asked for the cosine of the angle between two vectors with that product.

Orthogonal vectors

Two non-zero vectors are orthogonal (perpendicular) if they make an angle of 90∘90^\circ, that is, if

u⃗⋅v⃗=0 \vec u \cdot \vec v = 0

Ana and Pablo: a⃗⋅p⃗=0\vec a \cdot \vec p = 0. They have no genre in common; their profiles are perpendicular. In R4\mathbb{R}^4 with the standard product, (1,2,−3,0)(1, 2, -3, 0) and (0,3,2,1)(0, 3, 2, 1) are orthogonal: 0+6−6+0=00 + 6 – 6 + 0 = 0. And orthogonality depends on the product: (1,0,0)(1, 0, 0) and (0,1,0)(0, 1, 0) are orthogonal with the standard product, but with GG their product is g12=1≠0g_{12} = 1 \neq 0.

Saying that two vectors are orthogonal if their dot product is 1. It is 0. A dot product of 1 between two unit vectors would mean they are the same vector.

Orthogonal and orthonormal bases

A basis is orthogonal if its vectors are pairwise orthogonal, and orthonormal if, in addition, all of them are unit vectors. In terms of the Gram matrix in that basis:

  • BB is orthogonal   ⟺  \iff GG is diagonal.
  • BB is orthonormal   ⟺  \iff G=IG = I.

The standard basis is orthonormal with the standard product. To go from an orthogonal basis to an orthonormal one, just divide each vector by its norm.

The Gram matrix tells you if the basis is orthogonalThree Gram matrices of the standard dot product: for yellow, cyan and magenta, full; for the orthogonal basis from Gram-Schmidt, diagonal 2, 6, 3; and for the orthonormal basis, the identity. Arrows: Gram-Schmidt and dividing by the norms.any basis211121112full Gorthogonal200060003G diagonalorthonormal100010001G = IG-S÷ ‖u‖yellow, magenta, cyan → (1,1,0), (1,−1,2), (−1,1,1) → ÷ √2, √6, √3
Orthogonal: zeros off the diagonal. Orthonormal: also ones on it.

Why are they so popular? Because in an orthonormal basis the coordinates come out without solving any system: coordinate ii of u⃗\vec u is u⃗⋅e⃗i\vec u \cdot \vec e_i. And the dot product goes back to being the sum of products of coordinates.

The Gram-Schmidt process

Gram-Schmidt and the orthogonal projection are in the 2026/27 course guide, although they did not appear in the previous year’s notes. If your lecturer does not cover them, skip these two sections: the rest of the topic does not depend on them.

Before the formula, with two vectors and your head. You have v⃗1=(1,1,0) \vec v_1 = (1, 1, 0) and v⃗2=(1,0,1) \vec v_2 = (1, 0, 1) , and they are not perpendicular: their product is 1. You keep the first one as it is, u⃗1=v⃗1 \vec u_1 = \vec v_1 . From the second you remove a piece of the first, c u⃗1 c \, \vec u_1 , and you choose c c so that what is left is perpendicular to u⃗1 \vec u_1 :

(v⃗2−c u⃗1)⋅u⃗1=v⃗2⋅u⃗1−c (u⃗1⋅u⃗1)=1−2c=0⟹c=12 (\vec v_2 – c \, \vec u_1) \cdot \vec u_1 = \vec v_2 \cdot \vec u_1 – c \, (\vec u_1 \cdot \vec u_1) = 1 – 2c = 0 \quad \Longrightarrow \quad c = \tfrac12

That c c is the fraction in the formula: v⃗2⋅u⃗1u⃗1⋅u⃗1 \frac{\vec v_2 \cdot \vec u_1}{\vec u_1 \cdot \vec u_1} . You do not need to memorise it: it comes from asking for the remainder to be perpendicular. What does not change is what they span: u⃗2 \vec u_2 is a combination of v⃗1 \vec v_1 and v⃗2 \vec v_2 , and you get v⃗2 \vec v_2 back by adding c u⃗1 c \, \vec u_1 again.

With three vectors it is the same: from v⃗3 \vec v_3 you remove a piece of u⃗1 \vec u_1 and another of u⃗2 \vec u_2 . And here is the clever part: since u⃗1⋅u⃗2=0 \vec u_1 \cdot \vec u_2 = 0 , when you multiply by u⃗1 \vec u_1 the piece of u⃗2 \vec u_2 disappears, and each coefficient comes out on its own, with the same fraction. With the original v⃗ \vec v vectors that does not happen, because they are not perpendicular to each other.

The Gram-Schmidt process turns any basis {v⃗1,…,v⃗n}\{\vec v_1, \dots, \vec v_n\} into an orthogonal one {u⃗1,…,u⃗n}\{\vec u_1, \dots, \vec u_n\} that spans the same. The idea: from each vector you remove the part that “points” towards the ones you already have.

u⃗1=v⃗1,u⃗k=v⃗k−∑j<kv⃗k⋅u⃗ju⃗j⋅u⃗j u⃗j \vec u_1 = \vec v_1, \qquad \vec u_k = \vec v_k – \sum_{j < k} \frac{\vec v_k \cdot \vec u_j}{\vec u_j \cdot \vec u_j} \, \vec u_j

With v⃗1=(1,1,0)\vec v_1 = (1, 1, 0), v⃗2=(1,0,1)\vec v_2 = (1, 0, 1), v⃗3=(0,1,1)\vec v_3 = (0, 1, 1) (yellow, magenta and cyan, back to the colours) and the standard product:

  • u⃗1=(1,1,0)\vec u_1 = (1, 1, 0).
  • u⃗2=(1,0,1)−12(1,1,0)=(12,−12,1)\vec u_2 = (1, 0, 1) – \frac{1}{2} (1, 1, 0) = \left( \tfrac12, -\tfrac12, 1 \right), because v⃗2⋅u⃗1=1\vec v_2 \cdot \vec u_1 = 1 and u⃗1⋅u⃗1=2\vec u_1 \cdot \vec u_1 = 2. To avoid dragging fractions, I multiply it by 2: u⃗2=(1,−1,2)\vec u_2 = (1, -1, 2) (a multiple is still orthogonal).
  • u⃗3=(0,1,1)−12(1,1,0)−16(1,−1,2)=(−23,23,23)\vec u_3 = (0, 1, 1) – \frac{1}{2} (1, 1, 0) – \frac{1}{6} (1, -1, 2) = \left( -\tfrac23, \tfrac23, \tfrac23 \right), because v⃗3⋅u⃗1=1\vec v_3 \cdot \vec u_1 = 1, v⃗3⋅u⃗2=−1+2=1\vec v_3 \cdot \vec u_2 = -1 + 2 = 1 and u⃗2⋅u⃗2=6\vec u_2 \cdot \vec u_2 = 6. Multiplied by 32\tfrac32: u⃗3=(−1,1,1)\vec u_3 = (-1, 1, 1).

Check: (1,1,0)⋅(1,−1,2)=0(1, 1, 0) \cdot (1, -1, 2) = 0, (1,1,0)⋅(−1,1,1)=0(1, 1, 0) \cdot (-1, 1, 1) = 0 and (1,−1,2)⋅(−1,1,1)=−1−1+2=0(1, -1, 2) \cdot (-1, 1, 1) = -1 – 1 + 2 = 0. Dividing by the norms (2\sqrt2, 6\sqrt6, 3\sqrt3) gives an orthonormal basis.

The third vector, without skipping anything

The step for u⃗3 \vec u_3 is the one that gets compressed the most, so here it is slowly:

StepCalculationWhy
1v⃗3⋅u⃗1=0+1+0=1 \vec v_3 \cdot \vec u_1 = 0 + 1 + 0 = 1 How much v⃗3 \vec v_3 points towards u⃗1 \vec u_1
2u⃗1⋅u⃗1=2 \vec u_1 \cdot \vec u_1 = 2 , coefficient 12 \tfrac12 You divide so the remainder is perpendicular to u⃗1 \vec u_1
3v⃗3⋅u⃗2=0−1+2=1 \vec v_3 \cdot \vec u_2 = 0 – 1 + 2 = 1 With the new u⃗2 \vec u_2 , (1,−1,2) (1, -1, 2) , not with v⃗2 \vec v_2
4u⃗2⋅u⃗2=1+1+4=6 \vec u_2 \cdot \vec u_2 = 1 + 1 + 4 = 6 , coefficient 16 \tfrac16 The same fraction, now with u⃗2 \vec u_2
5(0,1,1)−(12,12,0)−(16,−16,13)=(−23,23,23) (0, 1, 1) – (\tfrac12, \tfrac12, 0) – (\tfrac16, -\tfrac16, \tfrac13) = (-\tfrac23, \tfrac23, \tfrac23) You subtract the two pieces, component by component
6u⃗3=(−1,1,1) \vec u_3 = (-1, 1, 1) You multiply by 32 \tfrac32 : it is still perpendicular

Why can you use (1,−1,2) (1, -1, 2) instead of (12,−12,1) (\tfrac12, -\tfrac12, 1) ? Because if you multiply u⃗2 \vec u_2 by a number k k , in the fraction the numerator gets multiplied by k k , the denominator by k2 k^2 and the vector by k k : the k k cancels and the piece you subtract is the same.

Check you’ve got it: what do you get if, in the step for u3, you subtract the projection onto v2 instead of onto u2?

You get (−1,12,12) (-1, \tfrac12, \tfrac12) , which is not perpendicular to u⃗1 \vec u_1 . Step by step: v⃗3⋅v⃗2=0+0+1=1 \vec v_3 \cdot \vec v_2 = 0 + 0 + 1 = 1 and v⃗2⋅v⃗2=2 \vec v_2 \cdot \vec v_2 = 2 , so you subtract 12(1,0,1) \tfrac12 (1, 0, 1) : (0,1,1)−(12,12,0)−(12,0,12)=(−1,12,12) (0, 1, 1) – (\tfrac12, \tfrac12, 0) – (\tfrac12, 0, \tfrac12) = (-1, \tfrac12, \tfrac12) . And when you check, (−1,12,12)⋅(1,1,0)=−12≠0 (-1, \tfrac12, \tfrac12) \cdot (1, 1, 0) = -\tfrac12 \neq 0 . It fails because v⃗2 \vec v_2 is not perpendicular to u⃗1 \vec u_1 : by removing the piece of v⃗2 \vec v_2 you put some of u⃗1 \vec u_1 back in.

Gram-Schmidt: subtract the projectionTwo panels in the plane. In the first, v2 and its projection on u1, drawn in coral along u1. In the second, the vector u2 = v2 minus that projection, perpendicular to u1.u₁ = v₁v₂projection1. remove the shadow of v₂ on u₁u₁ = v₁v₂u₂ = v₂ − proj2. what is left is perpendicular
Each vector loses what the previous ones already explained.

At each step, subtract the projections onto the new vectors u⃗j\vec u_j, not onto the original v⃗j\vec v_j. If you subtract onto the originals, the result is not orthogonal and you only notice when you check.

The orthogonal projection

Before the definition, in your head and with Ana. What part of my taste is explained by Ana’s? What can be explained with Ana are her multiples, t a⃗=(3t,4t,0) t \, \vec a = (3t, 4t, 0) : listening like her, for more or fewer hours. You have to choose t t so that t a⃗ t \, \vec a is as close to me as possible. The squared distance, expanding with the properties of the product, is

∥s⃗−t a⃗∥2=s⃗⋅s⃗−2t (s⃗⋅a⃗)+t2 (a⃗⋅a⃗)=9−20t+25t2 \lVert \vec s – t \, \vec a \rVert^2 = \vec s \cdot \vec s – 2t \, (\vec s \cdot \vec a) + t^2 \, (\vec a \cdot \vec a) = 9 – 20t + 25t^2

Trying a few values of t t :

t t t a⃗ t \, \vec a Squared distanceWhy
0(0,0,0) (0, 0, 0) 9You explain nothing: all my squared norm is left
25 \tfrac25 (65,85,0) (\tfrac65, \tfrac85, 0) 5The smallest: it is the projection
12 \tfrac12 (32,2,0) (\tfrac32, 2, 0) 214 \tfrac{21}{4} You go a bit too far: it grows again
1(3,4,0) (3, 4, 0) 14Copying Ana completely takes you further away than doing nothing

The minimum of 9−20t+25t2 9 – 20t + 25t^2 is at t=2050=25 t = \tfrac{20}{50} = \tfrac25 , and it is exactly the c c from Gram-Schmidt: s⃗⋅a⃗a⃗⋅a⃗=1025 \frac{\vec s \cdot \vec a}{\vec a \cdot \vec a} = \tfrac{10}{25} . It is not a coincidence: the closest point is the one where what is left is perpendicular to Ana’s direction. And Pythagoras holds: the squared norm of the projection is 3625+6425=4 \tfrac{36}{25} + \tfrac{64}{25} = 4 , what is left has squared norm 5, and 4+5=9=∥s⃗∥2 4 + 5 = 9 = \lVert \vec s \rVert^2 .

The orthogonal projection of v⃗\vec v onto a subspace WW is the vector of WW closest to v⃗\vec v. If {u⃗1,…,u⃗k}\{\vec u_1, \dots, \vec u_k\} is an orthogonal basis of WW:

projWv⃗=∑j=1kv⃗⋅u⃗ju⃗j⋅u⃗j u⃗j \text{proj}_W \vec v = \sum_{j=1}^{k} \frac{\vec v \cdot \vec u_j}{\vec u_j \cdot \vec u_j} \, \vec u_j

and what is left, v⃗−projWv⃗\vec v – \text{proj}_W \vec v, is orthogonal to all of WW. Its norm is the distance from v⃗\vec v to WW. Gram-Schmidt is nothing but this repeated: from each vector you remove its projection onto what came before.

With tastes: what part of what I listen to is explained by Ana? W=L{a⃗}W = L\{\vec a\}, a single direction:

projWs⃗=s⃗⋅a⃗a⃗⋅a⃗ a⃗=6+4+025(3,4,0)=25(3,4,0)=(65,85,0) \text{proj}_W \vec s = \frac{\vec s \cdot \vec a}{\vec a \cdot \vec a} \, \vec a = \frac{6 + 4 + 0}{25} (3, 4, 0) = \frac25 (3, 4, 0) = \left( \tfrac65, \tfrac85, 0 \right)
s⃗−projWs⃗=(45,−35,2),(45,−35,2)⋅(3,4,0)=125−125+0=0 \vec s – \text{proj}_W \vec s = \left( \tfrac45, -\tfrac35, 2 \right), \qquad \left( \tfrac45, -\tfrac35, 2 \right) \cdot (3, 4, 0) = \tfrac{12}{5} – \tfrac{12}{5} + 0 = 0

The “Ana-like” part of my taste is (65,85,0)(\tfrac65, \tfrac85, 0), and the rest, which includes all my classical, is perpendicular to it.

The projection of a vector onto a lineSergio’s vector (2,1,2) and Ana’s line (3,4,0). The projection (6/5, 8/5, 0) lies on the line, and the difference (4/5, −3/5, 2), dashed in green, is perpendicular to it.poprockclass.saproj = (6/5, 8/5, 0)proj = (s·a / a·a) a= (10/25)(3, 4, 0)s − proj = (4/5, −3/5, 2)⟂ a: 12/5 − 12/5 + 0 = 0what Ana does not explain
The projection is the closest point; what is left over is perpendicular.

Just for the curious. Least squares is a projection. If a system AX=BA X = B has no solution (more equations than unknowns, as when fitting a line to many points), you look for the XX whose AXA X is closest to BB: the projection of BB onto the columns of AA. It comes from the normal equations AtAX=AtBA^t A X = A^t B. For the line y=a+bxy = a + b x through (1,2)(1, 2), (2,3)(2, 3), (3,5)(3, 5), you get a=13a = \tfrac13, b=32b = \tfrac32. It is the linear regression you will see in statistics, and in MATLAB, A \ b already computes it when the system has no exact solution.

The cross product

Only in R3\mathbb{R}^3. The cross product of u⃗\vec u and v⃗\vec v is the vector w⃗=u⃗×v⃗\vec w = \vec u \times \vec v that satisfies:

  1. Norm: ∥w⃗∥=∥u⃗∥ ∥v⃗∥ sin⁡α\lVert \vec w \rVert = \lVert \vec u \rVert \, \lVert \vec v \rVert \, \sin \alpha, the area of the parallelogram they form.
  2. Direction: perpendicular to u⃗\vec u and to v⃗\vec v.
  3. Sense: given by the right-hand rule (or corkscrew rule).

In an orthonormal basis it is computed with a “determinant” with the basis vectors in the first row:

u⃗×v⃗=∣e⃗1e⃗2e⃗3u1u2u3v1v2v3∣=∣u2u3v2v3∣e⃗1−∣u1u3v1v3∣e⃗2+∣u1u2v1v2∣e⃗3 \vec u \times \vec v = \begin{vmatrix} \vec e_1 & \vec e_2 & \vec e_3 \\ u_1 & u_2 & u_3 \\ v_1 & v_2 & v_3 \end{vmatrix} = \begin{vmatrix} u_2 & u_3 \\ v_2 & v_3 \end{vmatrix} \vec e_1 – \begin{vmatrix} u_1 & u_3 \\ v_1 & v_3 \end{vmatrix} \vec e_2 + \begin{vmatrix} u_1 & u_2 \\ v_1 & v_2 \end{vmatrix} \vec e_3
s⃗×l⃗=∣e⃗1e⃗2e⃗3212221∣=(1−4) e⃗1−(2−4) e⃗2+(4−2) e⃗3=(−3,2,2) \vec s \times \vec l = \begin{vmatrix} \vec e_1 & \vec e_2 & \vec e_3 \\ 2 & 1 & 2 \\ 2 & 2 & 1 \end{vmatrix} = (1 – 4) \, \vec e_1 – (2 – 4) \, \vec e_2 + (4 – 2) \, \vec e_3 = (-3, 2, 2)

It is perpendicular to both: (−3,2,2)⋅(2,1,2)=−6+2+4=0(-3, 2, 2) \cdot (2, 1, 2) = -6 + 2 + 4 = 0 and (−3,2,2)⋅(2,2,1)=−6+4+2=0(-3, 2, 2) \cdot (2, 2, 1) = -6 + 4 + 2 = 0. Its norm, 9+4+4=17\sqrt{9 + 4 + 4} = \sqrt{17}, is the area of the parallelogram of s⃗\vec s and l⃗\vec l; and it agrees with the formula: sin⁡α=1−6481=179\sin \alpha = \sqrt{1 – \tfrac{64}{81}} = \tfrac{\sqrt{17}}{9}, and 3⋅3⋅179=173 \cdot 3 \cdot \tfrac{\sqrt{17}}{9} = \sqrt{17}.

Properties: u⃗×v⃗=−v⃗×u⃗\vec u \times \vec v = -\vec v \times \vec u (it is not commutative); it is perpendicular to both factors; if u⃗,v⃗≠0⃗\vec u, \vec v \neq \vec 0, u⃗×v⃗=0⃗\vec u \times \vec v = \vec 0 if and only if they are parallel; and (u⃗+v⃗)×z⃗=u⃗×z⃗+v⃗×z⃗(\vec u + \vec v) \times \vec z = \vec u \times \vec z + \vec v \times \vec z.

The cross product of Sergio and LauraThe parallelogram of Sergio (2,1,2) and Laura (2,2,1), and their cross product (−3,2,2) sticking out perpendicular to it. Beside, the two dot products that give 0 and the norm √17, equal to the area.poprockclass.sls × l = (−3, 2, 2)area √17perpendicular to both:(−3,2,2)·(2,1,2) = 0(−3,2,2)·(2,2,1) = 0‖s × l‖ = √17= 3 · 3 · sin α
Its norm is the area; its direction, the common perpendicular.

The cross product gives a vector perpendicular to a plane with a single calculation. It is what you will use in topic 8 for the equation of a plane, and here it gives you for free the implicit equation of a plane through the origin: the plane L{s⃗,l⃗}L\{\vec s, \vec l\} is −3x+2y+2z=0-3x + 2y + 2z = 0.

The scalar triple product

The scalar triple product of three vectors of R3\mathbb{R}^3, in an orthonormal basis, is the determinant of their components:

[u⃗,v⃗,w⃗]=u⃗⋅(v⃗×w⃗)=∣u1u2u3v1v2v3w1w2w3∣ [\vec u, \vec v, \vec w] = \vec u \cdot (\vec v \times \vec w) = \begin{vmatrix} u_1 & u_2 & u_3 \\ v_1 & v_2 & v_3 \\ w_1 & w_2 & w_3 \end{vmatrix}

In absolute value it is the volume of the parallelepiped they form. With Sergio, Laura and Pablo:

[s⃗,l⃗,p⃗]=∣212221004∣=4⋅(2⋅2−1⋅2)=8 [\vec s, \vec l, \vec p] = \begin{vmatrix} 2 & 1 & 2 \\ 2 & 2 & 1 \\ 0 & 0 & 4 \end{vmatrix} = 4 \cdot (2 \cdot 2 – 1 \cdot 2) = 8

If it is 0, the three vectors lie in the same plane: they are linearly dependent, the same thing the determinant said in topic 3. The one of the standard basis, [e⃗1,e⃗2,e⃗3][\vec e_1, \vec e_2, \vec e_3], is 1: the unit cube.

The same in MATLAB

dot, norm and cross do the standard dot product, the norm and the cross product; with another Gram matrix you write the formula as it is:

s = [2 1 2]; l = [2 2 1]; p = [0 0 4]; a = [3 4 0];
dot(s, l)                               % standard dot product
norm(s)                                 % norm
cosa = dot(s, l) / (norm(s) * norm(l))
acos(cosa) * 180 / pi                   % the angle in degrees
dot(a, p)                               % 0: orthogonal

Output:

ans =

     8

ans =

     3

cosa =

    0.8889

ans =

   27.2660

ans =

     0

acos gives the angle in radians; that is why it is multiplied by 180/π180 / \pi. Now with the Gram matrix GG, with the vectors written as rows:

G = [2 1 0; 1 2 0; 0 0 1];
s * G * l'                                              % row · G · column
sqrt(s * G * s')                                        % the norm with G
c = (s * G * l') / (sqrt(s * G * s') * sqrt(l * G * l'))
cross(s, l)
det([s; l; p])                                          % scalar triple product

Output:

ans =

    20

ans =

    4.2426

c =

    0.9428

ans =

    -3     2     2

ans =

     8

s * G * l' is exactly XtGYX^t G Y: s is a row and l' a column. If you write s' * G * l, MATLAB complains because the dimensions do not match. And Gram-Schmidt, with a loop that subtracts the projections onto the new vectors:

format rat
V = [1 1 0; 1 0 1; 0 1 1]';          % the original vectors, as columns
U = zeros(3);
for k = 1:3
    w = V(:, k);
    for j = 1:k-1                     % subtract the projection onto each u_j already computed
        w = w - (dot(V(:, k), U(:, j)) / dot(U(:, j), U(:, j))) * U(:, j);
    end
    U(:, k) = w;
end
U                                     % orthogonal columns
abs([dot(U(:,1), U(:,2)), dot(U(:,1), U(:,3)), dot(U(:,2), U(:,3))]) < 1e-12   % are they 0?

Output:

U =

       1              1/2           -2/3     
       1             -1/2            2/3     
       0              1              2/3     

ans =

  1×3 logical array

   1   1   1

The columns of U are (1,1,0)(1, 1, 0), (12,−12,1)(\tfrac12, -\tfrac12, 1) and (−23,23,23)(-\tfrac23, \tfrac23, \tfrac23), the paper ones before removing fractions. And the three products between different columns are 0: the check gives 1 1 1 (true all three times). It is compared with a tolerance, < 1e-12, because the computer works with decimals and a 0 can come out as 10−1610^{-16}; with format rat, those non-exact zeros show up as asterisks.

Try it in the MATLAB playground

In the website’s MATLAB playground you can build your own “recommender”:

% Who are you most like? Hours of pop, rock and classical
me = [2 1 2];
friends = [2 2 1; 0 0 4; 3 4 0];      % Laura, Pablo, Ana
for k = 1:size(friends, 1)
    f = friends(k, :);
    c = dot(me, f) / (norm(me) * norm(f));
    fprintf('Friend %d: cosine %.4f\n', k, c)
end

Things to look at:

  • Put your hours in me and your friends’ in friends. The highest cosine is your musical twin.
  • Change me to [4 2 4]: the cosines do not change. The cosine measures the profile, not the amount.
  • Add a friend [0 0 1] and compare with Ana: cosine 0, orthogonal.
  • Change dot(me, f) to me * G * f' (and the norm calls to the root of x * G * x') with the G above, and watch the similarity with Laura go up.

Summary

ConceptFormulaWatch out for
Standard dot productx1y1+⋯+xnynx_1 y_1 + \dots + x_n y_nFour properties: symmetric, linear, positive definite
Matrix expressionXtGYX^t G Y, gij=e⃗i⋅e⃗jg_{ij} = \vec e_i \cdot \vec e_jRow · GG · column
CongruenceG′=CtGCG' = C^t G CCC with the new basis as columns
Norm+u⃗⋅u⃗+\sqrt{\vec u \cdot \vec u}Positive, no ±
Unit vector±u⃗/∥u⃗∥\pm \vec u / \lVert \vec u \rVertHere there are two
Anglecos⁡α=u⃗⋅v⃗∥u⃗∥∥v⃗∥\cos \alpha = \frac{\vec u \cdot \vec v}{\lVert \vec u \rVert \lVert \vec v \rVert}With the product you are given
Orthogonalu⃗⋅v⃗=0\vec u \cdot \vec v = 00, not 1
Orthogonal / orthonormal basisGG diagonal / G=IG = IDivide by the norms
Gram-Schmidtu⃗k=v⃗k−∑v⃗k⋅u⃗ju⃗j⋅u⃗ju⃗j\vec u_k = \vec v_k – \sum \frac{\vec v_k \cdot \vec u_j}{\vec u_j \cdot \vec u_j} \vec u_jProject onto the new ones
Cross productDeterminant with e⃗1,e⃗2,e⃗3\vec e_1, \vec e_2, \vec e_3Only R3\mathbb{R}^3; perpendicular to both
Scalar triple productdet⁡(u⃗,v⃗,w⃗)\det(\vec u, \vec v, \vec w)Volume; 0 if coplanar

Three ideas to take away:

  • The dot product is the measuring rule: lengths (+u⃗⋅u⃗+\sqrt{\vec u \cdot \vec u}), angles (the cosine) and perpendiculars (product 0) come from it. Changing the Gram matrix changes every measurement.
  • In a basis, the product is row · GG · column, and GG holds in each entry the product of two basis vectors.
  • An orthonormal basis makes everything easy; Gram-Schmidt builds one by subtracting projections, and the cross product gives the perpendicular to two vectors in R3\mathbb{R}^3.

Now it is your turn: in the Euclidean space guided practice we solve five problems step by step, checked in MATLAB: a Gram matrix in another basis, angles with two dot products (and why you should round at the end), a basis that is orthogonal with respect to a GG, Gram-Schmidt with a projection and the cosine part as it appears in the exam. And to check you have got it, the Euclidean space exercises go from easy to hard and come with commented solutions and a quiz like the Campus ones. If you come without the previous topic, first review the vector spaces theory. Next comes topic 5, linear transformations and diagonalisation.

Next step: practiceEuclidean space — guided practice with music taste: Gram matrix, angles, orthonormal bases, Gram-Schmidt and the exam’s cosine (and the decimals that got away from me)

Did this article help you? Here is how you can support SergioLearns →