Vectors#


Revised

29 Jun 2023


Programming Environment#

import math
from   typing import List

What is a vector?#

a change in position \(\langle a,b\rangle\)

a point \((a,b)\in\mathbb{R}^2\)

a list of numbers \( \begin{bmatrix} a&b\\ \end{bmatrix} \)

any object which has both (1) a magnitude (e.g., length) and (2) a direction

visually, a vector looks like an arrow with (1) some length and (2) pointing in some direction

Note that although a vector arrow looks like a ray, the vector arrow does not mean that the vector goes to infinity; it just represents the vector’s direction.


Varieties of vectors#


Displacement Vector#

A vector can represent the change in position or displacement from one point to another.

Let \(P=(x_0,y_0),Q=(x_1,y_1)\in\mathbb{R}^2\) be two points in Cartesian space.

The displacement vector from \(P\) to \(Q\) can be calculated as

\(\vec{PQ}=\langle x_1-x_0,y_1-y_0\rangle\)

The displacement vector from \(Q\) to \(P\) is just

\(\vec{QP}=-\vec{PQ}=\langle x_0-x_1,y_0-y_1\rangle\)

Note that any points \(P,Q\in\mathbb{R}^2\) which satisfy

\( \begin{aligned} x_1-x_0&=a\\ y_1-y_0&=b\\ \end{aligned} \)

for some fixed \(a,b\) represent the same displacement vector \(\langle a,b\rangle\).

In other words, the location of a displacement vector does not matter. Two displacement vectors with the same length and direction are identical and indistinguishable.


[EXAMPLE]

\( P=(2,4),Q=(5,8) \implies \vec{PQ}=\langle5-2,8-4\rangle=\langle3,4\rangle \)

\( R=(-17,5),S=(-14,9) \implies \vec{RS}=\langle-14-(-17),9-5\rangle=\langle3,4\rangle \)

\(\vec{PQ}=\langle3,4\rangle\) and \(\vec{RS}=\langle3,4\rangle\) are the same displacement vector


Position Vector#

A vector can represent the position of a point.

Let \(P=(a,b)\in\mathbb{R}^2\) be a point in Cartesian space.

The position vector \(\langle a-0,b-0\rangle=\langle a,b\rangle\) is just the displacement vector from the origin \((0,0)\) to \(P\).

In other words, the position vector of a point \(P=(a,b)\in\mathbb{R}^2\) is just \(\langle a,b\rangle\).


Tangent Vector#

A vector can represent the direction of tangency at a certain point along a curve.

The length/magnitude of a tangent vector may not be relevant, only its direction. In such cases, we use the unit tangent vector.

Velocity is an example of a tangent vector: the velocity vector of an object is always tangent to the object’s path of motion, and the length/magnitude of this vector is the object’s speed.


Data/Information Vector#

A vector can be used to collect data for the purposes of thinking about that data geometrically or mathematically.


Notation#

A vector is denoted in the following ways.

arrow

\(\vec{v}\)

boldface

\(\mathbf{v}\)

A vector \(\mathbf{v}\in\mathbb{R}^2\) represented in terms of its components can be written in the following ways.

displacement vector

\(\langle a,b\rangle\)

position vector

\((a,b)\)

column vector

\( \begin{bmatrix} a\\b\\ \end{bmatrix} \)

row vector

\( \begin{bmatrix} a&b\\ \end{bmatrix} \)


Vector Operations#


Vector Addition#

Geometrically

tip to tail

Arithmetically, vector addition is calculated component-wise.

\( \langle a,b\rangle+\langle c,d\rangle =\langle a+c,b+d\rangle \)

def add2 (v : List,
          w : List) -> List:
  return [v[0] + w[0], v[1] + w[1]]

v = [1, 2]
w = [4, 4]

add2(v, w)
add2(v, [-1 * e for e in w])
[-3, -2]
def addn (v : List,
          w : List) -> List:
  return [x + y for (x, y) in zip(v, w)]

def addn (v : List,
          w : List) -> List:
  return [v[i] + w[i] for i in range(len(v))]

Scalar Multiplication (Scalar-Vector Multiplication)#

Geometrically

scaling

Arithmetically, scalar multiplication is calculated by distribution.

\( \mathbf{v}=\langle a,b\rangle \implies k\mathbf{v}=k\langle a,b\rangle=\langle ka,kb\rangle \)

Scalar multiplication can change the length of a vector, but cannot change its direction except in the case when \(k\lt0\) which orients the vector in the opposite direction.

def scalar_vector_mult (alpha : float,
                        v     : List) -> List:
  return [alpha * v[i] for i in range(len(v))]

[EXAMPLE]

\( \begin{aligned} &\langle1,3\rangle+3\langle-2,-1\rangle-2\langle2,-5\rangle\\ =&\langle1,3\rangle+\langle-6,-3\rangle+\langle-4,10\rangle\\ =&\langle1-6-4,3-3+10\rangle\\ =&\langle-9,10\rangle\\ \end{aligned} \)


Vector Properties#


Additive Commutativity#

Vector addition is defined in terms of a commutative operation (commutativity of field elements), so it is commutative.

Additive Associativity#

Vector addition is defined in terms of an associative operation (associativity of field elements), so it is associative.

Scalar-Multiplicative Associativity#

Distributivity of scalar-multiplication over vector addition#


Vector Parallelism#

Two vectors are parallel (and point in the same direction) if they are scalar multiples of each other.

\( \mathbf{v}\parallel\mathbf{w} \iff \mathbf{v}=k\mathbf{w}\lor\mathbf{w}=k\mathbf{v} \)

Two vectors are anti parallel (i.e., parallel but pointing in opposite directions) if \(k\lt0\).


Vector Magnitude#

The magnitude of a vector is calculated via the Pythagorean Theorem.

Let \(\mathbf{v}\) be a vector.

The magnitude of \(\mathbf{v}\in\mathbb{R}^2\) is

\( \begin{aligned} \|\mathbf{v}\|=\|\langle a,b\rangle\|=\sqrt{a^2+b^2} \end{aligned} \)

The magnitude of \(\mathbf{v}\in\mathbb{R}^3\) is

\( \begin{aligned} \|\mathbf{v}\|=\|\langle a,b,c\rangle\|=\sqrt{a^2+b^2+c^2} \end{aligned} \)

The magnitude of \(\mathbf{v}\in\mathbb{R}^n\) is

\( \begin{aligned} \|\mathbf{v}\|=\|\langle x_1,...,x_n\rangle\|=\sqrt{x_1^2+...+x_n^2} \end{aligned} \)


Vector Direction and the Unit Vector#

A vector whose magnitude is unity (i.e., whose length is one) is called a unit vector.

A nonzero vector’s direction is described by a parallel unit vector.

To scale a nonzero vector to unity, scalar multiply it by one over its magnitude.

Let \(\mathbf{v}\) be a vector.

The unit vector \(\mathbf{\hat{u}}\) of vector \(\mathbf{v}\) is

\( \mathbf{\hat{u}}= \begin{aligned} \frac{\mathbf{v}}{\|\mathbf{v}\|} \end{aligned} \)


Standard Basis Vectors#

The standard basis vectors are special unit vectors which together can describe any vector.

Any vector \(\mathbf{v}\in\mathbb{R}^n\) can be written as a linear combination of the standard basis vectors


The standard basis in \(\mathbb{R}^2\) consists of

\( \mathbf{\hat{i}}=\langle1,0\rangle \) one unit in the \(x\) direction

\( \mathbf{\hat{j}}=\langle0,1\rangle \) one unit in the \(y\) direction

Any vector \(\mathbf{v}\in\mathbb{R}^2=a\mathbf{\hat{i}}+b\mathbf{\hat{j}}\) for some \(a,b\in\mathbb{R}\)


[EXAMPLE]

\( \begin{aligned} \langle3,5\rangle =\langle3,0\rangle+\langle0,5\rangle =3\langle1,0\rangle+5\langle0,1\rangle =3\mathbf{\hat{i}}+5\mathbf{\hat{j}} \end{aligned} \)


The standard basis in \(\mathbb{R}^3\) consists of

\( \mathbf{\hat{i}}=\langle1,0,0\rangle \) one unit in the \(x\) direction

\( \mathbf{\hat{j}}=\langle0,1,0\rangle \) one unit in the \(y\) direction

\( \mathbf{\hat{k}}=\langle0,0,1\rangle \) one unit in the \(z\) direction

Any vector \(\mathbf{v}\in\mathbb{R}^3=a\mathbf{\hat{i}}+b\mathbf{\hat{j}}+c\mathbf{\hat{k}}\) for some \(a,b,c\in\mathbb{R}\)


Pythagorean Theorem in three dimensions

Let \(L=(a,b,c)\) be the line segment from the origin to the point \(a\) units along the x-axis, \(b\) units along the y-axis, and \(c\) units along the z-axis.

Let \(d\) be the line segment in the xy-plane from the origin to the point \((a,b,0)\).

\( \begin{aligned} L&=\sqrt{c^2+d^2}\\ d&=\sqrt{a^2+b^2}\\ \end{aligned} \implies L=\sqrt{c^2+(\sqrt{a^2+b^2})^2}=\sqrt{a^2+b^2+c^2} \)


n-vector#

A vector of \(n\) real numbers is called an \(n\)-vector over \(\mathbb{R}\).

The set of n-vectors over F#

Let \(\mathbb{F}\) be a field and let \(n\) be a positive integer.

A vector of \(n\) elements where each \(n_i\in\mathbb{F}\) is called an \(n\)-vector over \(\mathbb{F}\).

The set of \(n\)-vectors over \(\mathbb{F}\) is denoted \(\mathbb{F}^n\).

[EXAMPLE]

For example, the set of \(4\)-vectors over \(\mathbb{R}\) is denoted \(\mathbb{R}^4\).

Vectors are functions with a finite domain#

\( \mathbb{F}^n=\mathbb{F}^{\{0, 1, 2, 3, \dots, n - 1\}} \) may be interpreted as the set of functions from \(\{0, 1, 2, 3, \dots, n - 1\}\) to \(\mathbb{F}\).

[EXAMPLE]

For example, the \(4\)-vector over \(\mathbb{R}\)

\(\langle \pi, e, -1.0, 2.0 \rangle\)

is just the function

\( \begin{aligned} 0 &\mapsto \pi \\ 1 &\mapsto e \\ 2 &\mapsto -1.0 \\ 3 &\mapsto 2.0 \\ \end{aligned} \)

Example: the word-bag model of documents#

According to the word-bag model of documents, a document is a multiset (or “bag”) of words.

A multiset is like a set that can contain more than one copy of an element; and the number of copies is called the multiplicity of the element.

A bag of words is represented by a function \(f\) whose domain is the set of words \(\text{WORDS}\) and whose codomain is the set of real numbers \(\mathbb{R}\).

\( f : \text{WORDS} \to \mathbb{R} \)

The image of a word is its multiplicity.

The function \(f\) can be interpreted as a \(\text{WORDS}\)-vector over \(\mathbb{R}\).

Then \(\mathbb{R}^\text{WORDS}\) is the set of all \(\text{WORDS}\)-vectors over \(\mathbb{R}\), or the set of functions with domain \(\text{WORDS}\) and codomain \(\mathbb{R}\).

D-vector over F#

Let \(D\) be a finite set and let \(\mathbb{F}\) be a field.

A \(D\)-vector over \(\mathbb{F}\) is a function from \(D\) to \(\mathbb{F}\).

Then \(\mathbb{F}^D\) is the set of all \(D\)-vectors over \(\mathbb{F}\), or the set of functions with domain \(D\) and codomain \(\mathbb{F}\).

[EXAMPLE]

For example, \(GF(2)^n\) denotes the set of all \(n\)-vectors over \(GF(2)\), or the set of functions with domain \(\{0, 1, 2, 3, \dots, n - 1\}\) and codomain \(GF(2)\).

k-sparse vector#

A vector most of whose values are zero is called a sparse vector.

If no more than \(k\) of the elements are nonzero, the vector is called \(k\)-sparse.

A \(k\)-sparse vector can be represented using space proportional to \(k\).

What can be represented with vectors?#

Geometric points#

Sets and multisets#

Bit strings#

An \(n\)-bit binary string

\(10111011\)

is represented as an \(n\)-vector over \(GF(2)\)

\([1,0,1,1,1,0,1,1]\)

Attribute names and values#

A data set consists of observations or points each of which is represented by a collection of attribute names and attribute values; this collection in turn is represented by a function that maps attribute names to the corresponding values.

The state of a system at a point in time#

Finite probability distributions#

A finite probability distribution is a function from a finite domain to the real numbers.

Images#

A black and white \(m\times n\) image is a function from the set of pairs

\( \{ (i, j) \mid 0 \le i \lt m, 0 \le j \lt n \} \)

to the real numbers \(\mathbb{R}\).

The pixel-coordinate pair \((i, j)\) maps to a number called the pixel intensity.

[EXAMPLE]

Consider a \(4\times8\) (width by height) grayscale gradient where pixel intensity \(0\) represents black and \(255\) represents white.

\( f : \{ (i, j) | 0 \le i \lt 4, 0 \le j \lt 8 \} \to \{0, 1, 2, \dots, 255\} \)

{(i, j) : math.ceil(i * (255 / 8)) for j in range(4) for i in range(8)}
{(0, 0): 0,
 (1, 0): 32,
 (2, 0): 64,
 (3, 0): 96,
 (4, 0): 128,
 (5, 0): 160,
 (6, 0): 192,
 (7, 0): 224,
 (0, 1): 0,
 (1, 1): 32,
 (2, 1): 64,
 (3, 1): 96,
 (4, 1): 128,
 (5, 1): 160,
 (6, 1): 192,
 (7, 1): 224,
 (0, 2): 0,
 (1, 2): 32,
 (2, 2): 64,
 (3, 2): 96,
 (4, 2): 128,
 (5, 2): 160,
 (6, 2): 192,
 (7, 2): 224,
 (0, 3): 0,
 (1, 3): 32,
 (2, 3): 64,
 (3, 3): 96,
 (4, 3): 128,
 (5, 3): 160,
 (6, 3): 192,
 (7, 3): 224}

Representations#

Python List#

v = [math.pi, math.e, -1.0, 2.0]
v
[3.141592653589793, 2.718281828459045, -1.0, 2.0]

Python Dictionary#

v = {k : v for k, v in enumerate([math.pi, math.e, -1.0, 2.0])}
v
{0: 3.141592653589793, 1: 2.718281828459045, 2: -1.0, 3: 2.0}

Figures#

  • [W] Gibbs, Josiah

  • [W] Hamilton, William


Resources#


Terms#

  • [W] Quaternion

  • [W] Vector

  • [W] Vector Calculus


Bibliography#