Dot Product

Many abstract concepts that make linear algebra a powerful mathematical tool have their roots in plane geometry so we begin our study of dot product by reviewing basic properties of lengths and angles in the real two-dimensional plane ℝ². Guided by these geometrical properties, we formulate properties of dot product that further will be generalized in the following section. Dot product is used to define a magnitude of a vector that is called norm in mathematics.

 

ℝ² Motivation


Classical Pythagorean Theorem: If 𝑎 and b are the lengths of two sides of a right triangle, and if c is the length of its hypotenuse, then 𝑎² + b² = c².
Construct a square with side c and place four copies of the right triangle around it to form a larger square with side 𝑎 + b. The are of the larger square is equal to the area of the smaller square plus four times the area of the original triangle with sides 𝑎 and b:
Classical Pythagorean theorem
     
gr1 = Graphics[{Red, Opacity[.5], Rectangle[{0, 0}], Green, Opacity[.5], Triangle[{{0, .77}, {0, 1}, {.77, 1}}], (*Red,Arrow[{{.5,.5},{0,.77}}],Arrow[{{.5,.5},{.77,1}}],*) Blue, Opacity[.2], Rotate[Rectangle[{0.1, 0.1}, {.9, .9}], 100/6 Degree](*, Green,PointSize->Medium,Point[{.5,.5}]*)}, Epilog -> {Text["a", {0.03, .9}], Text["b", {.4, .97}], Text["c", {0.3, .88}]}, Frame -> {True, True, False, False}, FrameTicks -> None, FrameLabel -> {{None, None}, {"Cosine is posative: Cos(\[Theta]) > 0", None}}, PlotLabel -> "Classical Pythagorean Theorem Proof"]

\[ (a+b)^2 = c^2 + 4 \left( \frac{1}{2} \,ab \right) . \]
Simplify[(a + b)^2 == c^2 + 4 (1/2 a b)]
Hence,
\[ a^2 + 2ab + b^2 = c^2 + 2ab \qquad \Longrightarrow \qquad a^2 + b^2 = c^2 . \]
The length of any one side of a plane triangle (it needs not be a right triangle) is determined by the lengths of its other two sides and the cosine of the angle between them. This is a consequence of the Pythagorean theorem.
Theorem (Law of cosines): Let 𝑎 and b be the lengths of two sides of a plane triangle, let θ be the angle between two sides, and let c be the length of the third side. Then 𝑎² + b² − 2𝑎b cosθ = c².
The Pythagorean theorem ensures that
\begin{align*} c^2 &= \left( a - b\,\cos \theta \right)^2 + \left( b\,\sin\theta \right)^2 \\ &= a^2 -2ab\,\cos\theta + b^2 \cos^2 \theta + b^2 \sin^2 \theta \\ &= a^2 -2ab\,\cos\theta + b^2 \end{align*}
Clear[a, b, c];
Solve[c^2 == (a \[Minus] b Cos[\[Theta]])^2 + (b Sin[\[Theta]])^2, c][[2, 1, 2]] // FullSimplify;
%^2
a^2 + b^2 - 2 a b Cos[\[Theta]]
because cos² + sin² = 1.
TrigExpand[Cos[\[Theta]]^2 + Sin[\[Theta]]^2]
1
If θ = π/2, then cosθ = 0. This case corresponds to the right angle, considered previously.
\[Theta]1 = 30 Degree; a = 10; b = 5; Graphics[{Red, Thick, Dashing[{}], Circle[{0, 0}, 1, {.145 Pi, -(Pi/1350)}], Green, Opacity[.2], Triangle[{{0, 0}, {5, 0}, {5, b Sin[\[Theta]1]}}], Green, Opacity[.4], Triangle[{{5, 0}, {5, b Sin[\[Theta]1]}, {10, 0}}], Black, Line[{{5, .1}, {5.1, .1}}], Line[{{5.1, .1}, {5.1, 0}}], Black, Dashed, Line[{{5, 0}, {5, b Sin[\[Theta]1]}}]}, Epilog -> {Text[ "\[LongLeftArrow] a \[LongRightArrow]", {5, -.15}], Text["b", {2, 1.2}], Text["b Cos(\[Theta])", {3, .12}], Text["a-(b Cos(\[Theta]))", {7, .12}], Text["c", {8, 1.2}], Text[" \[Theta] = 30\[Degree]", {1.25, .2}], Rotate[Text["b Sin(\[Theta])", {4.8, 1}], 90 Degree]}, ImageSize -> 650, Frame -> False, FrameTicks -> None, FrameLabel -> {"Cos(\[Theta]) is positive if 0 < \[Theta] < \ \!\(\*FractionBox[\(\[Pi]\), \(2\)]\)", None, None, None}, PlotRange -> {{0, 10}, {-.5, 2.5}}]
\[Theta]2 = 120 Degree; a = 3; b = 5; Graphics[{Black, Line[{{0, .1}, {.1, .1}}], Line[{{.1, .1}, {.1, 0}}], Red, Thick, Dashing[{}], Circle[{-b Cos[\[Theta]2], 0}, .5, {(1.3 Pi)/2, -((3 Pi)/1350)}], Green, Opacity[.4], Triangle[{{0, 0}, {0, b Sin[\[Theta]2]}, {-b Cos[\[Theta]2], 0}}], Green, Opacity[.2], Triangle[{{-b Cos[\[Theta]2], 0}, {0, b Sin[\[Theta]2]}, {a - b Cos[\[Theta]2], 0}}], Black, Dashed, Line[{{0, 0}, {0, b Sin[\[Theta]2]}}], Line[{{0, 0}, {-b Cos[\[Theta]2], 0}}]}, Epilog -> {Text["a", {4, -.12}], Text["b", {1.6, 1.2}], Text["-b Cos(\[Theta])", {1, -.12}], Text["c", {3.2, 2}], Text[" \[Theta] = 120\[Degree]", {3.1, .45}], Rotate[Text["b Sin(\[Theta])", {-.3, 2}], 90 Degree]}, ImageSize -> 350, Frame -> False, FrameTicks -> None, FrameLabel -> {"Cos(\[Theta]) is negative if \!\(\*FractionBox[\(\ \[Pi]\), \(2\)]\) < \[Theta] < \[Pi]", None, None, None}, PlotRange -> {{-.5, 6}, {-.5, 4.5}}]
Cosine is positive: cosθ > 0.
     
Cosine is negative: cosθ < 0.
The following command finds the length (number of components) of a vector:
v = {3, 5};
Length[v]
Out[5]= 2

The law of cosines implies a familiar fact about plane triangles: the length of one side is not greater than the sum of the lengths of the other two sides.

Theorem (Triangle inequality): Let 𝑎, b, and c be the lengths of the sides of a plane triangle. Then
\[ c \le a+b . \]
Let θ be the angle between the sides whose lengths are 𝑎 and b. Since −cosθ ≤ 1, the law of cosines theorem tells us that
\[ c^2 = a^2 - 2ab\,\cos\theta + b^2 \le a^2 + 2ab\,\cos\theta + b^2 = (a+b)^2 . \]
Hence, c ≤ 𝑎 + b.
Let us consider the triangle formed by vectors
\[ {\bf a} = \begin{pmatrix} a_1 \\ a_2 \end{pmatrix} \qquad \mbox{and} \qquad {\bf b} = \begin{pmatrix} b_1 \\ b_2 \end{pmatrix} . \]
Angle between vectors
     
b3 = {.75, .75}; a3 = {1.5, .25}; c3 = {b3, a3}; arc3 = {Green, Circle[{0, 0}, .25, {.25, VectorAngle[b3, {.5, 0}]}]}; Show[ Graphics[{arc3, Directive[Red, Thick], Arrow[{{0, 0}, b3}], Directive[Green, Thick], Arrow[{b3, a3}], Directive[Blue, Thick], Arrow[{{0, 0}, a3}]}, PlotRangePadding -> .5, Axes -> True], Epilog -> {Rotate[ Text["\[Theta] = " <> ToString[VectorAngle[a3, b3]/Degree] <> "\[Degree]", {.45, .17}], 15 Degree], Text["b = " <> ToString[b3], {.8, .8}], Text["a= " <> ToString[a3], {1.75, .25}], Text["c", {1.1, .6}]}]

If we place c = 𝑎b beginning at b, it forms the third side of a triangle. Inspired by the Pythagorean theorem, we introduce the notation
\[ \| {\bf a} \| = \sqrt{a_1^2 + a_2^2} \]
to indicate the Euclidean length of the vector 𝑎. Then
\[ \| {\bf c} \|^2 = \left( a_1 - b_1 \right)^2 + \left( a_2 - b_2 \right)^2 . \]
The law of cosines tells us that
\[ \| {\bf a} \|^2 + \| {\bf b} \|^2 - 2 \,\| {\bf a} \| \| {\bf b} \| \cos\theta = \| {\bf c} \|^2 . \]
Thus,
\[ a_1^2 + a_2^2 + b_1^2 + b_2^2 - 2 \,\| {\bf a} \| \| {\bf b} \| \cos\theta = \left( a_1 - b_1 \right)^2 + \left( a_2 - b_2 \right)^2 . \]
Hence,
\[ a_1^2 + a_2^2 + b_1^2 + b_2^2 - 2 \,\| {\bf a} \| \| {\bf b} \| \cos\theta = a_1^2 - 2a_1 b_1 + b_1^2 + a_2^2 - 2a_2 b_2 + b_2^2 , \]
and therefore
\begin{equation} \label{EqDot.1} a_1 b_1 + a_2 b_2 = \| {\bf a} \| \| {\bf b} \| \cos\theta . \end{equation}
Mathematica has a dedicated command to determine an angle between two vectors by specifying the reference:
u = {2, 3}; v = {-3, 2};
PlanarAngle[{u, {0, 0}, v}]
\[Pi]/2
The left-hand side of Eq.\eqref{EqDot.1} is the dot product of vectors 𝑎 and b (written is rectangular coordinates) and is denoted by
\[ {\bf a} \cdot {\bf b} = a_1 b_1 + a_2 b_2 = \| {\bf a} \| \| {\bf b} \| \cos\theta . \]
The Euclidean length (called norm) and the dot product are related by
\[ \| {\bf a} \| = \left( {\bf a} \cdot {\bf a} \right)^{1/2} = \left( a_1^2 + a_2^2 \right)^{1/2} = \| {\bf a} \|_2 , \]
where we choose a positive branch for the square root (analytic function). Usually, the Euclidean norm is supplied with subscript "2" because there are known many other norms (that are discussed in the following section).
TrueQ[Norm[a3] == Sqrt[a3.a3]]
True

The prime example of dot operation is work that is defined as the scalar product of force and displacement. The presence of cos(θ) ensures the requirement that the work done by a force perpendicular to the displacement is zero.

Example 1: Suppose that a boat is sailing at 7 knots, following a course of 015° (that is, 15° east of north), on a bay that has a 3-knot current setting in the direction 073° (that is, 73° east of north).

In navy, the expression made good is standard navigation terminology for the actual course and speed of a vessel over the bottom. The velocity vector s for the ketch and c for the current are shown in the figure, in which the vertical axis points due north.
Sailing vector
     
x1 = Solve[Cos[20 Degree] == adj/2, adj][[1, 1, 2]] // N; y1 = Solve[x1^2 + y1^2 == 4, y1][[2, 1, 2]]; c = {x1, y1}

We find s and c by using Mathematica:
\[ {\bf s} = \left[ 7\,\cos 75^{\circ} , 7\,\sin 75^{\circ} \right] = \left[ 1.81173 , 6.76148 \right] \]
N[7*Cos[75 Degree]]
1.81173
N[7*Sin[75 Degree]]
6.76148
and
\[ {\bf c} = \left[ 3\,\cos 17^{\circ} , 3\,\sin 17^{\circ} \right] = \left[ 2.86891 , 0.877115 \right] . \]
N[3*Cos[17 Degree]]
2.86891
N[3*Sin[17 Degree]]
0.877115
By adding s and c, we find the vector v = s + c representing the course and speed of the ketch over the bottom---that is, the course and speed made good. Hence, we have v = [4.68064 , 6.76148]. Therefore, the speed of the boat is
\[ \| {\bf v} \| \approx \sqrt{(4.68064)^2 + (6.76148)^2} \approx 8.2235 \mbox{ knots}. \]
The course made good is given by
\[ 90^{\circ} - \arctan \left( \frac{6.76148}{4.68064} \right) \approx 34.693^{\circ} . \]
That is, the course is 034°.

Example 2: Suppose that the captain of our boat realizes the importance of keeping track of the current. He wishes to sail in 6 hours to a harbor that bears 110° and is 42 nautical miles away. That is, he wishes to make good the course 110° and the speed 6 knots. He knows from a tide and current table that the current is setting due south at 3 knots.

The vector s = vc
     

In vector diagram, we again represent the course and speed to be made good by a vector v and the velocity of the current by c. The correct course and speed to follow are represented by the vector s, which is obtained by computing
\begin{align*} {\bf s} &= {\bf v} - {\bf c} \\ &= \left[ 6\,\cos 40^{\circ}, -6\,\sin 40^{\circ} \right] - \left[ 0 , -3 \right] \\ &= \left[ 4.59627 , - 3.85673 \right] - \left[ 0 , -3 \right] = \left[ 4.59627 , -0.85673 \right] . \end{align*}
Thus, the captain should steer course
\[ 90^{\circ} - \arctan \left( -\frac{0.85673}{4.59627} \right) \approx 90^{\circ} + 10.5586 = 100..5586^{\circ} , \]
and should proceed at
\[ \| {\bf s} \| \approx \sqrt{(0.85673)^2 + (4.59627)^2} \approx 4.67543 \mbox{ knots}. \]

 

Dot product in ℝn and ℂn


Motivated by two-dimensional case, we extend dot product to a finite-dimensional vector space under arbitrary field. However, this operation between two vectors can be implemented only when a basis is chosen for the corresponding vector space, allowing one to render coordinates .
The dot product of two vectors of the same size \( {\bf x} = \left[ x_1 , x_2 , \ldots , x_n \right] \) and \( {\bf y} = \left[ y_1 , y_2 , \ldots , y_n \right] \) (independently whether they are columns or rows) is the scalar, denoted either by \( {\bf x} \cdot {\bf y} : \)
\begin{equation} \label{EqDot.2} {\bf x} \cdot {\bf y} = x_1 y_1 + x_2 y_2 + \cdots + x_n y_n , \end{equation}
when entries are real, or
\begin{equation} \label{EqDot.3} {\bf x} \cdot {\bf y} = {\bf x}^{\ast} {\bf y} = \overline{x_1} y_1 + \overline{x_2} y_2 + \cdots + \overline{x_n} y_n , \end{equation}
when entries are complex. Here \( (a + {\bf j}\,b )^{\ast} = \overline{a + {\bf j}\,b} = a - {\bf j}\,b \) is the complex conjugate to 𝑎 + jb ∈ ℂ.

Using definition of the dot product, we can verify its following properties. For x, y, z ∈ ℂn and k ∈ ℂ, we have
  1. x ⋅ x = 0 if and only if x = 0;
  2. (x + y) ⋅ z = x ⋅ z + y ⋅ z;
  3. x ⋅ (ky) = k(x ⋅ y);
  4. \( {\bf x} \cdot {\bf y} = \overline{{\bf y} \cdot {\bf x}} . \)
This list of properties suggests that the dot product it is a positive-definite bilinear mapping
\[ \mbox{dot product}\,:\, V^{\ast} \times V \mapsto \mathbb{F} \ \left( = \mathbb{R} \mbox{ or } \mathbb{C} \right) , \]
where V* is the dual space. However, in complex case, the first component does not enjoy multiplication by a complex scalar, but by its complex conjugate; this means that
\[ \left( k\,{\bf x} \right) \cdot {\bf y} = \overline{k}\,{\bf x} \cdot {\bf y} . \]
Note: Dot product for complex vector spaces can be defined as
\[ {\bf x} \cdot {\bf y} = x_1 \overline{y_1} + x_2 \overline{y_2} + \cdots + x_n \overline{y_n} . \]
This definition is usually used in mathematics and we mark it as West Coast  . Our definition is mostly used in physics and engineering; correspondingly, we mark it as East Coast. Both definitions lead to the same conclusions and it does not matter which one is applied, but you have to be consistent.

Example 3: Let us calculate the dot prodict of the following two complex vectors:
\[ {\bf x} \cdot {\bf y} , \qquad {\bf x} = \begin{bmatrix} 1 + {\bf j} \\ -2 + 3{\bf j} \\ 3 - {\bf j} \end{bmatrix} , \quad {\bf y} = \begin{bmatrix} 2 - {\bf j} \\ 4 + 2{\bf j} \\ 6 - 2{\bf j} \end{bmatrix} . \]
According to definition, we have
\[ {\bf x} \cdot {\bf y} = \left( 1 - {\bf j} \right) \left( 2 - {\bf j} \right) + \left( -2 - 3{\bf j} \right) \left( 4 + 2{\bf j} \right) + \left( 3 + {\bf j} \right) \left( 6 - 2{\bf j} \right) . \]
We ask Mathematica to do this arithmetic:
(1 - I)*(2 - I) + (-2 - 3*I)*(4 + 2*I) + (3 + I)*(6 - 2*I)
19 - 19 I
However, when we use a standard command, Mathematica provides
Dot[{1 + I, -2 + 3*I, 3 - I}, {2 - I, 4 + 2*I, 6 - 2*I}]
5 - 3 I
because it just multiplies the compoenents. So you need to enter complex conjugate entries into the first vector:
Dot[{1 - I, -2 - 3*I, 3 + I}, {2 - I, 4 + 2*I, 6 - 2*I}]
19 - 19 I

A unit vector u is a vector whose length equals one: \( {\bf u} \cdot {\bf u} =1 . \) We say that two vectors x and y are perpendicular if their dot product is zero.

Josiah Gibbs
The dot product was first introduced by the American physicist and mathematician Josiah Willard Gibbs (1839--1903) in the 1880s.

With Euclidean norm ‖·‖2, the dot product formula

\[ {\bf x} \cdot {\bf y} = \| {\bf x} \|_2 \, \| {\bf y} \|_2 \, \cos \theta , \tag{1} \]
defines θ, the angle between two vectors. This allows us to define the angle between two vectors:
\begin{equation} \label{EqDot.4} \theta = \arccos \left( \frac{{\bf a} \cdot {\bf b}}{\| {\bf a} \| \cdot \| {\bf b} \| } \right) . \end{equation}
One can use the distributive property of the dot product to show that if (ax, ay, az) and (bx, by, bz) represent the components of a and b along the axes x, y, and z, then
\[ {\bf a} \cdot {\bf b} = a_x b_x + a_y b_y + a_z b_z . \]
From the definition of the dot product, we can draw an important conclusion. If we divide both sides of a · b = |a| |b| cos θ by |a|, we get
\[ \frac{{\bf a} \cdot {\bf b}}{|{\bf a}|} = |{\bf b}|\,\cos\theta \qquad \iff \qquad \left( \frac{{\bf a}}{|{\bf a}|} \right) \cdot {\bf b} = \hat{\bf e}_a \cdot {\bf b} = |{\bf b}|\,\cos\theta \]
Noting that |b| cos θ is simply the projection of b along a, we conclude that in order to find the perpendicular projection of a vector b along another vector a, take dot product of b with \( \hat{\bf e}_a , \) the unit vector along a.

The orthogonal projection
     
b = {1, 1}; l = {1, .25}; p = a = Projection[b, l]; x = b.a/Norm[a]^2 a; c = b - x;
arc1 = {Green, Circle[{0, 0}, .25, {.25, VectorAngle[b, {.5, 0}]}]}; PlanarAngle[{0, 0} -> {b, p}]; Show[ Graphics[{Line[{{p[[1]] + .02, p[[2]] + .07}, {p[[1]] + .03, p[[2]] + .02}}], Line[{{p[[1]] - .01, p[[2]] + .07}, {p[[1]] + .02, p[[2]] + .08}}], arc1, InfiniteLine[{0, 0}, l], Directive[Red, Thick], Arrow[{{0, 0}, b}], Directive[Green, Thick], Arrow[{{0, 0}, c}], Directive[Blue, Thick], Arrow[{{0, 0}, p}], Directive[Black], Directive[Black, Dotted], Line[{c, {1, 1}}], Line[{p, b}]}, PlotRangePadding -> .5, Axes -> True], GridLines -> {{Projection[b, l][[1]]}, {Projection[b, l][[2]]}}, Epilog -> {Rotate[ Text["\[Theta] = " <> ToString[VectorAngle[a, b]/Degree] <> "\[Degree]", {.43, .17}], 15 Degree], Text["b", {1.05, 1.05}], Text["a", {1.2, .25}], Text["c", {-.3, .6}]}]

Example 4: What is the angle between i and i + j + 2k?
\begin{align*} \theta &= \arccos \left( \frac{{\bf i} \cdot ({\bf i} + {\bf j} + 2 {\bf k})}{\| {\bf i} \| \cdot \| {\bf i} + {\bf j} + 2 {\bf k} \| } \right) \\ &= \arccos \left( \frac{1}{\sqrt{6}} \right) \approx 1.15026. \end{align*}
We check with Mathematica:
VectorAngle[{1, 0, 0}, {1, 1, 2}]
ArcCos[1/Sqrt[6]]

The dot product of any two vectors of the same dimension can be done with the dot operation given as Dot[vector 1, vector 2] or with use of a period “. “ .

{1,2,3}.{2,4,6}
28
Dot[{1,2,3},{3,2,1} ]
10

============================== check ==================

The dot product of two vectors of the same size \( {\bf x} = \left[ x_1 , x_2 , \ldots , x_n \right] \) and \( {\bf y} = \left[ y_1 , y_2 , \ldots , y_n \right] \) (regardless of whether they are columns or rows because Mathematica does not distinguish rows from columns) is the number, denoted either by \( {\bf x} \cdot {\bf y} \) or \( \left\langle {\bf x} , {\bf y} \right\rangle ,\)

\[ \left\langle {\bf x} , {\bf y} \right\rangle = {\bf x} \cdot {\bf y} = x_1 y_1 + x_2 y_2 + \cdots + x_n y_n , \]
when entries are real, or
\[ \left\langle {\bf x} , {\bf y} \right\rangle = {\bf x} \cdot {\bf y} = \overline{x_1} y_1 + \overline{x_2} y_2 + \cdots + \overline{x_n} y_n , \]

when entries are complex. Here \( \overline{\bf x} = \overline{a + {\bf j}\, b} = a - {\bf j}\,b \) is a complex conjugate of a complex number x = a + jb.

The dot product of any two vectors of the same dimension can be done with the dot operation given as Dot[vector 1, vector 2] or with use of a period “. “ .

{1,2,3}.{2,4,6}
28
Dot[{1,2,3},{3,2,1} ]
10
With Euclidean norm ‖·‖2, the dot product formula
\[ {\bf x} \cdot {\bf y} = \| {\bf x} \|_2 \, \| {\bf y} \|_2 \, \cos \theta , \]
defines θ, the angle between two vectors. The dot product was first introduced by the American physicist and mathematician Josiah Willard Gibbs (1839--1903) in the 1880s. ■

=========================================================

         
 Augustin-Louis Cauchy    Viktor Yakovlevich Bunyakovsky    Hermann Amandus Schwarz
For any norm, the Cauchy--Bunyakovsky--Schwarz (or simply CBS) inequality holds:
\[ | {\bf x} \cdot {\bf y} | \le \| {\bf x} \| \, \| {\bf y} \| . \]
The inequality for sums was published by the French mathematician and physicist Augustin-Louis Cauchy (1789--1857) in 1821, while the corresponding inequality for integrals was first proved by the Russian mathematician Viktor Yakovlevich Bunyakovsky (1804--1889) in 1859. The modern proof (which is actually a repetition of the Bunyakovsky's one) of the integral inequality was given by the German mathematician Hermann Amandus Schwarz (1843--1921) in 1888. With Euclidean norm, we can define the dot product as
\[ {\bf x} \cdot {\bf y} = \| {\bf x} \| \, \| {\bf y} \| \, \cos \theta , \]
where \( \theta \) is the angle between two vectors. ■

 

  1. What is the angle between the vectors i + j and i + 3j?
  2. What is the area of the quadrilateral with vertices at (1, 1), (4, 2), (3, 7) and (2, 3)?
  1. Vector addition
  2. Tea
  3. Milk