Math 33A Week 1: Vectors and Matrices

Vectors

Vectors

A vector in the physical sense is some quantity with both a direction and magnitude.

For example, in 2D space, a vector can be represented by an arrow:
vector in 2d
We don't necessarily assign a position to such vectors; instead, we can assume (for some standard representation) that vectors start at the origin. In this convention, vectors in nn-dimensional space can be identified with the position of their head and thus can also be regarded as position vectors.

Lines

Recall that last week, we found that the solution to
{x+y+z=3x−y+z=1\begin{cases}x+y+z=3\\ x-y+z=1\end{cases}
was x=2−t,y=1x=2-t, y=1, and z=tz=t for any number tt. If we take the interpretation of this system being the intersection of planes in 3D space, then our solution is the collection of vectors
[2−t1t],\begin{bmatrix}2-t\\1\\t\end{bmatrix},
which form a line in 3D space.

Vector notation

We can write vectors as ordered-tuples (x,y,z)(x,y,z) or as "columns"
[xyz].\begin{bmatrix}x\\ y\\ z\end{bmatrix}.
We will take the convention that a (column) vector is a column. We may write vv or v⃗\vec{v} to refer to a variable. We will also refer to the individual values x,y,zx,y,z of a vector as its coordinates or components.

Adding vectors

You may have seen that in the physical intepretation of vectors, we may add two vectors x⃗\vec{x} and y⃗\vec{y}. This was done by translating y⃗\vec{y} so that the "tail" of y⃗\vec{y} is on the "head" of x⃗\vec{x}. Then the sum x⃗+y⃗\vec{x}+\vec{y} is the vector starting at the "tail" of x⃗\vec{x} and going to the "head" of y⃗\vec{y}:
adding vectors
If you work out some examples, you will notices that the coordinates of the sum x⃗+y⃗\vec{x}+\vec{y} are the sum of the corresponding coordinates of x⃗\vec{x} and y⃗\vec{y}.

More specifically, if we have two vectors
x⃗=[x1⋮xn],y⃗=[y1⋮yn],\vec{x} = \begin{bmatrix}x_1\\ \vdots \\ x_n\end{bmatrix},\quad \vec{y}=\begin{bmatrix}y_1 \\ \vdots \\ y_n\end{bmatrix}, then we define
x⃗+y⃗=[x1+y1⋮xn+yn]\vec{x}+\vec{y} = \begin{bmatrix}x_1 + y_1 \\ \vdots \\ x_n + y_n \end{bmatrix}

Scaling vectors (scalar multiplication)

In the physical sense, we also had a notion of scaling a vector vv by a constant kk. If kk is positive, then the scaled vector kvkv would be in the same direction of vv but with kk times the length. If kk is negative, then the direction of kvkv would flip 180 degrees and the length of kvkv would be ∣k∣|k| times the length of vv. As examples, consider:
vector scaling
Some explicit examples will reveal that the coordinates of kvkv are kk times the coordinates of vv.

More specifically, if we have a vector
v=[v1⋮vn],v=\begin{bmatrix}v_1 \\ \vdots \\ v_n\end{bmatrix},
then the scaled vector is defined to be
kv=[kv1⋮kvn].kv = \begin{bmatrix}kv_1 \\ \vdots \\ kv_n \end{bmatrix}.

Matrices

You may have seen matrices in the past. They may have been introduced formally as tables of numbers. For example, we might have
(123456).\begin{pmatrix} 1 & 2 & 3 \\ 4& 5 & 6\end{pmatrix}.
Moreover, we refer to the size of a matrix by its number of rows ×\times its number of columns.

2×32\times 3 Matrix

B=(123456)B= \begin{pmatrix} 1 & 2 & 3 \\ 4& 5 & 6\end{pmatrix}

3×43\times 4 Matrix

C=(123456789101112)C= \begin{pmatrix} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9 & 10 & 11 & 12\end{pmatrix}

Matrices

A m×nm\times n matrix is a table of numbers with exactly mnmn entries arranged in mm rows and nn columns:
(a11a12⋯a1na21a22⋯a2n⋮⋮⋱⋮am1am2⋯amn).\begin{pmatrix}a_{11} & a_{12} & \cdots & a_{1n}\\ a_{21} & a_{22} & \cdots & a_{2n}\\ \vdots & \vdots & \ddots & \vdots\\ a_{m1} & a_{m2} & \cdots & a_{mn} \end{pmatrix}.
The entry aija_{ij} refers to the number in the iith row and jjth column.

Vectors

A vector
v=[v1⋮vn]v = \begin{bmatrix}v_1 \\ \vdots \\ v_n\end{bmatrix}
is an n×1n\times 1 matrix! Note that the parantheses/bracket notations are irrelevant.

Augmented matrices

Recall that the augmented matrix for a linear system of equations
{a11x1+⋯+a1nxn=b1⋮am1x1+⋯+amnxn=bm\begin{cases}a_{11}x_1+\cdots&+ a_{1n}x_n = b_1\\&\vdots\\ a_{m1}x_1+\cdots&+ a_{mn}x_n=b_m \end{cases}
is
(a11⋯a1nb1⋮⋱⋮⋮am1⋯amnbm)\left(\begin{array}{ccc|c}a_{11} & \cdots & a_{1n} &b_1\\ \vdots & \ddots & \vdots &\vdots \\ a_{m1} & \cdots & a_{mn} & b_m\end{array}\right)
The coefficients for the system were labelled as such to be consistent with the matrix formulation.

Adding and scaling matrices

Just as we defined for vectors, we can add and scale matrices. We just do these two operations "entry-wise".

Matrix-vector multiplication

Let's go back to a linear system
{a11x1+⋯+a1nxn=b1⋮am1x1+⋯+amnxn=bm\begin{cases}a_{11}x_1+\cdots&+ a_{1n}x_n = b_1\\&\vdots\\ a_{m1}x_1+\cdots&+ a_{mn}x_n=b_m \end{cases}and its augmented matrix
(a11⋯a1nb1⋮⋱⋮⋮am1⋯amnbm).\left(\begin{array}{ccc|c}a_{11} & \cdots & a_{1n} &b_1\\ \vdots & \ddots & \vdots &\vdots \\ a_{m1} & \cdots & a_{mn} & b_m\end{array}\right). Let AA denote the matrix of coefficients and bb the vector of RHS values so that the augmented matrix is
(Ab).\left(\begin{array}{c|c}A & b\end{array}\right).
Moreover, if we let
x=(x1⋮xn)x=\begin{pmatrix}x_1 \\ \vdots \\ x_n\end{pmatrix}
be the vector of variables, then it is very natural to represent our linear system as
Ax=b.Ax=b.

To make any sense, we need define matrix-vector multiplication. Of course, we should use the linear system as a guide. Note that the linear system can be equivalent written as a vector equation:
x1(a11⋮am1)+x2(a12⋮am2)+⋯+xn(a1n⋮amn)=(b1⋮bm)x_1\begin{pmatrix}a_{11}\\ \vdots \\ a_{m1}\end{pmatrix} + x_2\begin{pmatrix}a_{12}\\ \vdots \\ a_{m2}\end{pmatrix} +\cdots + x_n\begin{pmatrix}a_{1n}\\ \vdots \\ a_{mn}\end{pmatrix} = \begin{pmatrix}b_1\\ \vdots \\ b_m\end{pmatrix}

To ensure consistency we define matrix-vector multiplication as:

Matrix-vector multiplication

Let AA be a m×nm\times n matrix and xx a vector in nn dimensions (a n×1n\times 1 matrix). If the columns of AA are A1,…,AnA_1,\dots, A_n so that
A=(A1⋯An),A = \begin{pmatrix}A_1 & \cdots & A_n\end{pmatrix}, then we define
Ax=x1A1+x2A2+⋯+xnAn,Ax = x_1A_1 + x_2A_2 + \cdots + x_nA_n,
which is a vector in mm dimensions (m×1m\times 1 matrix). Component-wise, we have
Ax=(∑i=1na1jxj⋮∑j=1namjxj)Ax = \begin{pmatrix}\sum_{i=1}^n a_{1j}x_j \\ \vdots \\ \sum_{j=1}^n a_{mj}x_j\end{pmatrix}

Matrices are functions or transformations

You may be familiar with funcitons that map/transform a number xx to some value f(x)f(x). For example f(x)=x2f(x)=x^2 maps a number to its square.

In the same sense, a m×nm\times n matrix AA maps a vector in nn dimensions to a vector in mm dimensions. Moving forward we will denote the set of vectors in dd dimensions as Rd\R^d. Using this notation, AA is a function that inputs a vector in Rn\R^n and outputs a vector in Rm\R^m. In shorthand:
Rn→ARm\R^n \xrightarrow[]{A} \R^m

Size of vectors in the matrix-vector multiplication

We only defined the matrix-vector multiplication when the size (number of rows) of a vector equals the number of columns of the matrix. For short hand if we write the sizes of the matrix and vector next to each other
(m×n)⏟A⋅(n×1)⏟x\underbrace{(m\times n)}_A\cdot \underbrace{(n\times 1)}_x
then the inner numbers (nn in this case) must match. For example, a matrix-vector multiplication with sizes
(3×2)⋅(3×1)(3\times 2)\cdot (3\times 1)
is not defined.

Exercises

Determine the matrix-vector product or if it is not defined

  1. [0132][2−3]\begin{bmatrix}0 & 1 \\ 3& 2\end{bmatrix}\begin{bmatrix}2 \\ -3\end{bmatrix}
  2. [123456][12]\begin{bmatrix}1 & 2 \\ 3& 4 \\ 5 & 6\end{bmatrix}\begin{bmatrix}1\\2\end{bmatrix}
  3. [123456][78]\begin{bmatrix}1 & 2 & 3 \\ 4 & 5 & 6\end{bmatrix}\begin{bmatrix}7 \\8\end{bmatrix}
  4. [123][123]\begin{bmatrix}1 & 2 & 3\end{bmatrix}\begin{bmatrix}1 \\2 \\ 3\end{bmatrix}
  5. [5][7]\begin{bmatrix}5\end{bmatrix}\begin{bmatrix}7\end{bmatrix}
  6. AeiAe_iwhere AA is a m×nm\times n matrix with columns A1,A2,…,AnA_1,A_2,\dots, A_n and eie_i is a vector in Rn\R^n with all its components being 00 with the exception of its iith component which is 1. We call eie_i a standard basis vector in Rn\R^n.

Solution: For 6, the answer is Aei=AiAe_i = A_i. So applying AA to eie_i extracts the iith column AiA_i. Note that AA is entirely determined by its columns and thus entirely determined by how it behaves when applied to eie_i.

Matrix multiplication

Recall that we can compose functions. For example if
f(x)=x2f(x) = x^2
and
g(x)=sin⁡(x),g(x)= \sin(x),
then the composition of ff with gg is another function
(f∘g)(x)=f(g(x))=(sin⁡(x))2(f\circ g)(x) = f(g(x)) = (\sin(x))^2

Structurally, we have
f∘g:R→gR→fRf\circ g : \R \xrightarrow[]{g}\R \xrightarrow[]{f} \R
Since we think of matrices as functions, it is natural that we should be able to compose them! Let's suppose we have a m×nm\times n matrix AA and an k×mk\times m matrix B. So we have
Rn→ARm\R^n \xrightarrow[]{A} \R^m
and
Rm→BRk.\R^m \xrightarrow[]{B} \R^k.
Then if we have some vector xx in Rn\R^n, we can apply AA to it to get a vector AxAx in Rm\R^m. Then we can apply BB to this vector AxAx to get a vector B(Ax)B(Ax) in Rk\R^k. Since this is the process of funciton composition, we can define the compostion BABA as
(BA)x=B(Ax).(BA)x = B(Ax).
Note: We put the parentheses around BABA to emphasize that it is a single function.

In particular, we have
BA:Rn→ARm→BRk.BA: \R^n \xrightarrow[]{A}\R^m \xrightarrow[]{B}\R^k.
For now, let us assume that BABA is itself a matrix (we will see later in the course why BA is a matrix, but for now it might be expected since both AA and BB are matrices). Since it maps Rm\R^m to Rk\R^k, it should be a k×mk\times m matrix.

If BABA is a k×mk\times m matrix, then what does it look like?

Recall from above that applying a matrix to eie_i extracts its iith column. Using this we see that
(BA)ei=B(Aei)=BAi(BA)e_i = B(Ae_i) = BA_i
where AiA_i is the iith column vector of AA. Thus we must have that
BA=(BA1BA2⋯BAn).BA = \begin{pmatrix}BA_1 & BA_2 & \cdots & BA_n\end{pmatrix}.
So BABA is just BB applied to the columns of AA.

Now if we think of AA and BB as matrices instead of functions, then this derivation gives us a formula for matrix multiplication:

Matrix multiplication

If AA is an m×nm\times n matrix and BB a k×mk\times m matrix, then the matrix product BABA is defined as
BA=(B(a11⋮am1)B(a12⋮am2)⋯B(a1n⋮amn))BA = \begin{pmatrix}B\begin{pmatrix}a_{11} \\ \vdots \\ a_{m1}\end{pmatrix} & B\begin{pmatrix}a_{12} \\ \vdots \\ a_{m2}\end{pmatrix} & \cdots & B\begin{pmatrix}a_{1n} \\ \vdots \\ a_{mn}\end{pmatrix} \end{pmatrix}
which is to say that the columns of BABA are BB applied to the columns of AA. Entrywise, we have
(BA)ij=(B(a1j⋮amj))i=∑k=1nbikakj(BA)_{ij}=\left(B\begin{pmatrix}a_{1j} \\ \vdots \\ a_{mj}\end{pmatrix}\right)_i= \sum_{k=1}^nb_{ik}a_{kj}

Sizes of matrices in matrix multiplication

Because we only defined matrix-vector multiplication for when the size of the vector matched the number of columns of the matrix, the matrix multiplication BABA is only defined when the output size (number of rows) of AA equals the input size (number of columns) of BB. More succinctly, if BB is k×lk\times l and AA is m×nm\times n, then writing their sizes together
(k×l)⏟B⋅(m×n)⏟A\underbrace{(k\times l)}_B\cdot \underbrace{(m\times n)}_A
shows that the matrix mutliplication is only defined when l=ml=m. For example,
(2×3)⋅(3×1)(2\times 3)\cdot (3\times 1)
is a well-defined matrix multiplication, but
(2×3)⋅(2×3)(2\times 3)\cdot (2 \times 3)
is not.

Exercises

Determine the following matrix products, if they are defined.

  1. (100−210−1201)(11162221212451)\begin{pmatrix}1 & 0 & 0\\ -2 & 1 & 0\\ -12 & 0 & 1\end{pmatrix}\begin{pmatrix}1 & 1 & 1 & 6\\ 2& 2& 2 & 12\\ 12& 4 &5 &1\end{pmatrix}What do you notice about this matrix multiplication?
  2. (100010001)(123456789)\begin{pmatrix}1 & 0 & 0 \\ 0 & 1 & 0\\ 0 & 0 & 1\end{pmatrix}\begin{pmatrix}1 & 2 & 3 \\ 4 & 5 & 6\\ 7 & 8 & 9 \end{pmatrix}
  3. (263145)(123123)\begin{pmatrix}2 & 6 \\ 3& 1 \\4 & 5\end{pmatrix}\begin{pmatrix}1 & 2 & 3\\ 1& 2 & 3 \end{pmatrix}
  4. (263145)(123123123)\begin{pmatrix}2 & 6 \\ 3& 1 \\4 & 5\end{pmatrix}\begin{pmatrix}1 & 2 & 3\\ 1& 2 & 3 \\ 1 & 2 & 3\end{pmatrix}
Exercise

Let AA be a 3×23\times 2 matrix. If
A(10)=(123)A\begin{pmatrix}1\\ 0\end{pmatrix}= \begin{pmatrix}1\\ 2\\ 3\end{pmatrix}
and
A(01)=(456),A\begin{pmatrix}0 \\1\end{pmatrix} = \begin{pmatrix}4 \\ 5 \\6\end{pmatrix},
then what is AA?