# Linear Algebra Notes

Notes on some linear algebra topics. Sometimes I find things are just stated as being obvious, for example, the dot product of two orthogonal vectors is zero. Well... why is this? The result was a pretty simple but nonetheless it took a little while to think it through properly. Hence, these notes... they started of as my musings on the "why", even if the "why" might be obvious to the rest of the world!

A lot of these notes are now just based on the amazing Khan Academy linear algebra tutorials. In fact, id say the vast majority are... they are literally just notes on Sal's lectures!

Another resource that is really worth watching is 3 Blue 1 Brown's series "The essence of linear algebra".

## Vector Stuff

### Vector Spaces

References:

A vector is an element of a vector space. A vector space, also known as a linear space, $V$, is a set which has addition and scalar multiplication defined for it and satisfies the following for any vectors $\stackrel{\to }{u}$, $\stackrel{\to }{v}$, and $\stackrel{\to }{w}$ and scalars $c$ and $d$:

 1 Closed under addition: $\stackrel{\to }{u}+\stackrel{\to }{v}\in V$ 2 Communative: $\stackrel{\to }{u}+\stackrel{\to }{v}=\stackrel{\to }{v}+\stackrel{\to }{u}$ 3 Associative: $\left(\stackrel{\to }{u}+\stackrel{\to }{v}\right)+\stackrel{\to }{w}=\stackrel{\to }{u}+\left(\stackrel{\to }{v}+\stackrel{\to }{w}\right)$ 4 Additive identity: $\stackrel{\to }{0}\in U,\text{i.e.,}\stackrel{\to }{u}+\stackrel{\to }{0}=\stackrel{\to }{u}$ 5 Inverse: $\mathrm{\forall }\stackrel{\to }{u}\in V,\mathrm{\exists }-\stackrel{\to }{u}|\stackrel{\to }{u}+\left(-\stackrel{\to }{u}\right)=\stackrel{\to }{0}$ 6 Closed under scalar multiply: $c\stackrel{\to }{u}\in V$ 7 Distributive: $c\left(\stackrel{\to }{u}+\stackrel{\to }{v}\right)=c\stackrel{\to }{u}+c\stackrel{\to }{v}$ 8 Distributive: $\left(c+d\right)\stackrel{\to }{u}=c\stackrel{\to }{u}+d\stackrel{\to }{u}$ 9 Distributive: $c\left(d\stackrel{\to }{u}\right)=\left(cd\right)\stackrel{\to }{u}$ 10 Multiply identity: $1\stackrel{\to }{u}=\stackrel{\to }{u}$

#### Functions Spaces

First let's properly define a function. If $X$ and $Y$ are sets and we have $x\in X$ and $y\in Y$, we can form a set $F$ that consists of ordered pairs $\left({x}_{i},{y}_{j}\right)$. If it is the case that $\left({x}_{1},{y}_{1}\right)\in F\cap \left({x}_{1},{y}_{2}\right)\in F\phantom{\rule{0.278em}{0ex}}⟹\phantom{\rule{0.278em}{0ex}}{y}_{1}=={y}_{2}$, then $F$ is a function and we write $y=F\left(x\right)$. This is called being "single valued", i.e., each input to the function is unambiguous. Note, $F\left(x\right)$ is not a function, it is the value returned by the function: $F$ is the function that defines the mapping from elements in $X$ (the domain) to the elements in $Y$ (the range).

One example of a vector space is the set of real-valued functions of a real variable, defined on the domain $\left[a\le x\le b\right]$. I.e., we're talking about $\left\{{f}_{1},{f}_{2},\dots ,{f}_{n}\right\}$ where each ${f}_{i}$ is a function. In other words, ${f}_{i}:\mathbb{R}\to \mathbb{R}$ with the aforementioned restriction on the domain.

We've said that a vector is any element in a vector space, but usually we thing of this in terms of, say, $\left[x,y\right]\in {\mathbb{R}}^{2}$. We can also however, given the above, think of functions as vectors: the function-as-a-vector being the "vector" of ordered pairs that make up the mapping between domain and range. So in this case the set of function is still like a set of vectors and with scalar multiplication and vector addition defined appropriately the rules for a vector space still hold!

#### What Isn't A Vector Space

It sounded a lot like everything was a vector space to me! So I did a quick bit of googling and found the paper "Things that are/aren't vector spaces". It does a really good example of showing how in maths we might build up a model of something and expect it to behave "normally" (i.e., obeys the vector space axioms), but in fact doesn't, in which case it becomes a lot harder to reason about them. This is why vectors spaces are nice... we can reason about them using logic and operations we are very familiar with and feel intuitive.

### Linear Combinations

A linear combination of vectors is one that only uses the addition and scalar multiplication of those variables. So, given two vectors, $\stackrel{\to }{a}$ and $\stackrel{\to }{b}$ the following are linear combinations: $0\stackrel{\to }{a}+0\stackrel{\to }{b}\phantom{\rule{0ex}{0ex}}5\stackrel{\to }{a}-2.5\stackrel{\to }{b}\phantom{\rule{0ex}{0ex}}-123\stackrel{\to }{a}+\pi \stackrel{\to }{b}$ This can be generalise to say that for any set of vectors that a linear combination of those vectors is .

### Spans

The set of all linear combinations of a set of vectors $\left\{\stackrel{\to }{{v}_{1}},\stackrel{\to }{{v}_{2}},\dots ,\stackrel{\to }{{v}_{n}}\right\}$ is called the span of those vectors: $\mathrm{span}\left(\stackrel{\to }{{v}_{1}},\stackrel{\to }{{v}_{2}},\dots ,\stackrel{\to }{{v}_{n}}\right)=\left\{{c}_{1}\stackrel{\to }{{v}_{1}}+{c}_{2}\stackrel{\to }{{v}_{2}}+\cdots +{c}_{n}\stackrel{\to }{{v}_{n}}\phantom{\rule{0.278em}{0ex}}|\phantom{\rule{0.278em}{0ex}}{c}_{i}\in \mathbb{R}\right\}$ The span can also be refered to as the generating set of vectors for a subspace.

In the graph to the right there are two vectors $\stackrel{\to }{a}$ and $\stackrel{\to }{b}$. The dotted blue lines show all the possible scalings of the vectors. The vectors span those lines. The green lines show two particular scalings of $\stackrel{\to }{a}$ added to all the possible scalings of $\stackrel{\to }{b}$. One can use this to imagine that if we added all the possible scalings of $\stackrel{\to }{a}$ to all the possible scalings of $\stackrel{\to }{b}$ we would reach every coordinate in ${\mathbb{R}}^{2}$. Thus, we can say that the set of vectors $\left\{\stackrel{\to }{a},\stackrel{\to }{b}\right\}$ spans ${\mathbb{R}}^{2}$, or $\mathrm{span}\left(\stackrel{\to }{a},\stackrel{\to }{b}\right)={\mathbb{R}}^{2}$.

From this we may be tempted to say that any set of two, 2d, vectors spans ${\mathbb{R}}^{2}$ but we would be wrong. Take for example $\stackrel{\to }{a}$ and $\stackrel{\to }{b}=-\alpha \stackrel{\to }{a}$. These two variables are co-linear. Because they span the same line, no combination of them can ever move off that line. Therefore they do not span ${\mathbb{R}}^{2}$.

Lets write the above out a little more thoroughly... $\stackrel{\to }{a}=\left[\begin{array}{c}{a}_{1}\\ {a}_{2}\end{array}\right],\stackrel{\to }{b}=\left[\begin{array}{c}-\alpha {a}_{1}\\ -\alpha {a}_{2}\end{array}\right]$ The span of these vectors is, by our above definition: $\mathrm{span}\left(\stackrel{\to }{a},\stackrel{\to }{b}\right)=\left\{{c}_{1}\left[\begin{array}{c}{a}_{1}\\ {a}_{2}\end{array}\right]+{c}_{2}\left[\begin{array}{c}-\alpha {a}_{1}\\ -\alpha {a}_{2}\end{array}\right]\mid {c}_{i}\in \mathbb{R}\right\}$ Which we can re-write as: $\begin{array}{rl}\mathrm{span}\left(\stackrel{\to }{a},\stackrel{\to }{b}\right)& =\left\{{c}_{1}\left[\begin{array}{c}{a}_{1}\\ {a}_{2}\end{array}\right]-\alpha {c}_{2}\left[\begin{array}{c}{a}_{1}\\ {a}_{2}\end{array}\right]\mid {c}_{i}\in \mathbb{R}\right\}\\ & =\left\{\left({c}_{1}-\alpha {c}_{2}\right)\left[\begin{array}{c}{a}_{1}\\ {a}_{2}\end{array}\right]\mid {c}_{i}\in \mathbb{R}\right\}\end{array}$ ... which we can clearly see is just the set of all scaled vectors of $\stackrel{\to }{a}$. Plainly, any co-linear set of 2d vectors will not span ${\mathbb{R}}^{2}$.

### Linear Independence

We saw above that the set of vectors $\left\{\stackrel{\to }{a},-\alpha \stackrel{\to }{a}\right\}$ are co-linear and thus did not span ${\mathbb{R}}^{2}$. The reason for this is that they are linealy dependent, which means that one or more vectors in the set are just linear combinations of other vectors in the set.

For example, the set of vectors $\left\{\left[1,0\right],\left[0,1\right],\left[2,3\right]\right\}$ spans ${\mathbb{R}}^{2}$, but $\left[2,3\right]$ is redundant because we can remove it from the set of vectors and still have a set that spans ${\mathbb{R}}^{2}$. In other words, it adds no new information or directionality to our set.

A set of vectors will be said to be linearly dependent when: ${c}_{1}\stackrel{\to }{{v}_{1}}+\cdots +{c}_{n}\stackrel{\to }{{v}_{n}}=\stackrel{\to }{0}\mid \mathrm{\exists }\left\{{c}_{i}\mid {c}_{i}\ne 0\right\}$ Thus a set of vectors is linearly independent when the following is met: ${c}_{1}\stackrel{\to }{{v}_{1}}+\cdots +{c}_{n}\stackrel{\to }{{v}_{n}}=\stackrel{\to }{0}\mid \mathrm{\forall }\left\{{c}_{i}\mid {c}_{i}=0\right\}$ Sure, this is a definition, but why does this mean that the set is linearly dependent?

Think of vectors in a ${\mathbb{R}}^{2}$. For any two vectors that are not co-linear, there is no combination of those two vectors that can get you back to the origin unless they are both scaled by zero. The image to the left is trying to demonstrate that. If we scale $\stackrel{\to }{a}$, no matter how small we make that scaling, we cannot find a scaling of $\stackrel{\to }{b}$ that when added to $\stackrel{\to }{a}$ will get us back to the origin. Thus we cannot find a linear combination ${c}_{a}{v}_{a}+{c}_{b}{v}_{b}=\stackrel{\to }{0}$ where ${c}_{a}$ and/or ${c}_{b}$ does not equal zero.

This shows that neither vector is a linear combination of the other, because if it where, we could use a non-zero scaling of one, added to the other, to get us back to the origin.

We can also show that two vectors are linearly independent when their dot product is zero. This is covered in a latter section.

Another way of thinking about LI is that there is only one solution to the equation $A\stackrel{\to }{x}=\stackrel{\to }{0}$.

### Linear Subspace

If $V$ is a set of vectors in ${\mathbb{R}}^{n}$, then $V$ is a subspace of ${\mathbb{R}}^{n}$ if and only if:

1. $V$ contains the zero vector: $\stackrel{\to }{0}\in V$
2. $V$ is closed under scalar multiplication: $\stackrel{\to }{x}\in V,\alpha \in \mathbb{R}\phantom{\rule{0.278em}{0ex}}⟹\phantom{\rule{0.278em}{0ex}}\alpha \stackrel{\to }{x}\in V$
3. $V$ is closed under addition: $\stackrel{\to }{a}\in V,\stackrel{\to }{b}\in V\phantom{\rule{0.278em}{0ex}}⟹\phantom{\rule{0.278em}{0ex}}\stackrel{\to }{a}+\stackrel{\to }{b}\in V$

What these rules mean is that, using linear operations, you can't do anything to "break" out of the subspace using vectors from that subspace. Hence "closed".

Surprising, at least for me, was that the zero vector is actually a subspace of ${\mathbb{R}}^{n}$ because the set $\left\{\stackrel{\to }{0}\right\}$ obeys all of the above rules.

A very useful thing is that a span is always a valid subspace. Take, for example, $V=\mathrm{span}\left({v}_{1},{v}_{2},{v}_{3}\right)$. We can show that it is a valid subspace by checking that it objects the above 3 rules.

First, does it contain the zero vector? Recall that a span is the set of all linear combinations of the span vectors. So we know that the following linear combination is valid, and hence the span contains the zero vector. $0{\stackrel{\to }{v}}_{1}+0{\stackrel{\to }{v}}_{2}+0{\stackrel{\to }{v}}_{3}=\stackrel{\to }{0}$ Second, is it closed under scalar multiplication? Because the span is the set of all linear combinations, for any set of scalars $\left\{{a}_{1},{a}_{2},{a}_{3}\right\}$... ${a}_{1}{\stackrel{\to }{v}}_{1}+{a}_{2}{\stackrel{\to }{v}}_{2}+{a}_{3}{\stackrel{\to }{v}}_{3}=\stackrel{\to }{x}$ ... must also be in the subspace, by definition of a subspace!

Third, is it closed under vector addition? Well, yes, the same argument as made above would apply.

Interestingly, using the same method as above, we can see that even something trivial, like the $\mathrm{span}\left(\left[{a}_{1},{a}_{2}\right]\right)$, which is just a line, is a subspace of ${\mathbb{R}}^{2}$.

It can also be shown that any subspace basis will have the same number of elements. We say that the dimension of a subspace is the number of elements in a basis for the subspace. So, for example, if we had a basis for our subspace consisting of 13 vectors, the dimension of the subspace would be lucky 13.

### Basis Of A Subspace

Recall, $V=\mathrm{span}\left({\stackrel{\to }{v}}_{1},\dots ,{\stackrel{\to }{v}}_{n}\right)$ $V$ is a subspace of ${\mathbb{R}}^{n}$ (where each vector ${\stackrel{\to }{v}}_{i}\in {\mathbb{R}}^{n}$). We also know that a span is the set of all possible linear combinations of these vectors.

If we choose a subset of $V$, $S$, where all the vectors in $S$ are linearly independent, an we can write any vector in $V$ as a linear combination of vectors in $S$, then we say that $S$ is a basis for $V$.

$S$ acts as a "minimal" set of vectors required to span $V$. I.e., if you added any other vector to $S$ it is superfluous, because it would be a linear combination of the vectors already in $S$. You don't add any new information.

Put more formally: Let $V$ be a subspace of ${\mathbb{R}}^{n}$. A subset ${\stackrel{\to }{v}}_{1},{\stackrel{\to }{v}}_{2},\dots ,{\stackrel{\to }{v}}_{k}$ is a basis for $V$ iff the following are true:

1. The vectors ${\stackrel{\to }{v}}_{1},{\stackrel{\to }{v}}_{2},\dots ,{\stackrel{\to }{v}}_{k}$ span $V$, and
2. They are linearly independent.

A subspace can have an infinite number of basis, but there are standard basis. For example in ${\mathbb{R}}^{2}$ the standard basis is $\left\{\left[1,0\right],\left[0,1\right]\right\}$. The rule of invariance of dimension states that two bases for a subspace contain the same number of vectors. The number of elements in the basis for a subspace is called the subspace's dimension, denoted as $\mathrm{dim}\left(W\right)$, where $W$ is the subspace.

Thus, we can say that every subspace $W$ of ${\mathbb{R}}^{n}$ has a basis and $\mathrm{dim}\left(W\right)\le n$.

A basis is a good thing because we can break down any element in the space that the basis defines into a linear combination of basic building blocks, i.e. the basis vectors.

To find a basis use the following method:

1. Form a matrix where the jth column vector is the jth vector ${w}_{j}$.
2. Reduce the matrix to row-echelon form.
3. Tak the column vectors that contain a pivot and these are the basis vectors.

TODO discuss the canonical vectors in R2 and R3. $\left[1,0\right]$, $\left[0,1\right]$... but we could also have $\left[1,0\right]$, $\left[1,1\right]$.

TODO unique coefficients. implied by the linear independence

TODO most important basis are orthogonal and orthonormal.

Orthonormal are good because we can find the coefficient in the new basis easily: ${\alpha }_{k}={\stackrel{\to }{w}}_{k}\stackrel{˙}{x}$

### The Dot Product

#### Definition

This is a good reference.

The dot product is one definition for a vector multiplication that results in a scalar. Given two equal-length vectors, the dot product looks like this: $\left[\begin{array}{c}{a}_{1}\\ {a}_{2}\\ ⋮\\ {a}_{n}\end{array}\right]\cdot \left[\begin{array}{c}{b}_{1}\\ {b}_{2}\\ ⋮\\ {b}_{n}\end{array}\right]={a}_{1}{b}_{1}+{a}_{2}{b}_{2}+\cdots +{a}_{n}{b}_{n}$ Written more succinctly we have: $x\cdot y=\sum _{1}^{n}{x}_{i}{y}_{i}$ The dot product is important because it will keep popping up in many places. Some particular uses are to calculate the length of a vector and to show that two vectors are linearly independent.

#### Properties

The operation has the following properties:

 Commutative: $\stackrel{\to }{v}\cdot \stackrel{\to }{w}=\stackrel{\to }{w}\cdot \stackrel{\to }{v}$ Distributive: $\left(\stackrel{\to }{v}+\stackrel{\to }{w}\right)\cdot \stackrel{\to }{x}=\stackrel{\to }{v}\cdot \stackrel{\to }{x}+\stackrel{\to }{w}\cdot \stackrel{\to }{x}$ Associative $\left(c\stackrel{\to }{v}\right)\cdot \stackrel{\to }{w}=c\left(\stackrel{\to }{v}\cdot \stackrel{\to }{w}\right)$ Cauchy-Schwartz Inequality $\stackrel{\to }{x}\cdot \stackrel{\to }{y}\le |\stackrel{\to }{x}\cdot \stackrel{\to }{y}|\le ‖\stackrel{\to }{x}‖‖\stackrel{\to }{y}‖$ $|\stackrel{\to }{x}\cdot \stackrel{\to }{y}|=‖\stackrel{\to }{x}‖‖\stackrel{\to }{y}‖\phantom{\rule{0.278em}{0ex}}⟹\phantom{\rule{0.278em}{0ex}}\stackrel{\to }{x}=c\stackrel{\to }{y}$, where $c$ is non-zero. Vector Triangle Inequality $‖\stackrel{\to }{x}+\stackrel{\to }{y}‖\le ‖\stackrel{\to }{x}‖+‖\stackrel{\to }{y}‖$

#### Angle Between Vectors

The dot product also defines the angle between vectors. Take two unit vectors $\stackrel{^}{a}$ and $\stackrel{^}{b}$. We can calculate: We know that: $\mathrm{cos}\left({\theta }_{a}\right)={a}_{x}\phantom{\rule{0.278em}{0ex}}\text{and}\phantom{\rule{0.278em}{0ex}}\mathrm{sin}\left({\theta }_{a}\right)={a}_{y}$ $\mathrm{cos}\left({\theta }_{b}\right)={b}_{x}\phantom{\rule{0.278em}{0ex}}\text{and}\phantom{\rule{0.278em}{0ex}}\mathrm{sin}\left({\theta }_{b}\right)={b}_{y}$ And we know that: $\mathrm{cos}\left(\theta \right)=\mathrm{cos}\left({\theta }_{a}-{\theta }_{b}\right)=\mathrm{cos}\left({\theta }_{a}\right)\mathrm{cos}\left({\theta }_{b}\right)+\mathrm{sin}\left({\theta }_{a}\right)\mathrm{sin}\left({\theta }_{b}\right)$ Therefore, by substitution: $\begin{array}{rl}\mathrm{cos}\left(\theta \right)& ={a}_{x}{b}_{x}+{a}_{y}{b}_{y}\\ & =a\cdot b\end{array}$ Thus, $\mathrm{cos}\left(\theta \right)=a\cdot b$ describes the angle between unit vectors. If the vectors are not unit vectors then the angle is defined, in general, by: $\mathrm{cos}\left(\theta \right)=\frac{1}{‖\stackrel{\to }{a}‖‖\stackrel{\to }{b}‖}\stackrel{\to }{a}\cdot \stackrel{\to }{b}$

#### Vector Length

$\stackrel{\to }{a}\cdot \stackrel{\to }{a}=‖\stackrel{\to }{a}{‖}^{2}\phantom{\rule{0ex}{0ex}}\therefore ‖\stackrel{\to }{a}‖=\sqrt{\stackrel{\to }{a}\cdot \stackrel{\to }{a}}$

### Vector Transposes And The Dot Product

In linear algebra vectors are implicitly column vectors. I.e., when we talk about $\stackrel{\to }{v}$ we mean: $\stackrel{\to }{v}=\left[\begin{array}{c}{v}_{1}\\ {v}_{2}\\ ⋮\\ {v}_{n}\end{array}\right]$ Thus, the transpose of $\stackrel{\to }{v}$ is a row vector: ${\stackrel{\to }{v}}^{T}=\left[\begin{array}{cccc}{v}_{1}& {v}_{2}& \cdots & {v}_{n}\end{array}\right]$ We can then do vector multiplication of the two like so: $\begin{array}{rl}{\stackrel{\to }{v}}^{T}\stackrel{\to }{v}& =\left[\begin{array}{cccc}{v}_{1}& {v}_{2}& \cdots & {v}_{n}\end{array}\right]\left[\begin{array}{c}{v}_{1}\\ {v}_{2}\\ ⋮\\ {v}_{n}\end{array}\right]\\ & ={v}_{1}\cdot {v}_{1}+{v}_{2}\cdot {v}_{2}+\cdots +{v}_{n}\cdot {v}_{n}\\ & =\stackrel{\to }{v}\cdot \stackrel{\to }{v}\end{array}$ So, in general ${\stackrel{\to }{v}}^{T}\stackrel{\to }{w}=\stackrel{\to }{v}\cdot \stackrel{\to }{w}={\stackrel{\to }{w}}^{T}\stackrel{\to }{v}$.

### Dot Product With Matrix Vector Product

If $A$ is an mxn matrix and $\stackrel{\to }{x}\in {\mathbb{R}}^{n}$ then $A\stackrel{\to }{x}\in {\mathbb{R}}^{m}$.

Then, if $\stackrel{\to }{y}\in {\mathbb{R}}^{m}$ then $\left(A\stackrel{\to }{v}\right)\cdot \stackrel{\to }{y}$ is also well defined and: Thus we can say $\left(A\stackrel{\to }{x}\right)\cdot \stackrel{\to }{y}=\stackrel{\to }{x}\cdot \left({A}^{T}\stackrel{\to }{y}\right)$.

### Unit Length Vectors

A unit vector is a vector that has a length of 1. If $\stackrel{^}{u}$ is a vector (notice the special symbol used) then we defined its length as: $\mathrm{length}\left(\stackrel{^}{u}\right)=‖\stackrel{^}{u}‖=\sqrt{{u}_{1}^{2}+{u}_{2}^{2}+\cdots +{u}_{n}^{2}}$ Thus if a vector is a unit vector then $‖\stackrel{^}{u}‖=1$.

Interesting we can also write $‖\stackrel{\to }{u}{‖}^{2}=u\stackrel{˙}{u}$.

To construct a unit vector where $\sqrt{{u}_{1}^{2}+{u}_{2}^{2}+\cdots +{u}_{n}^{2}}=1$, we need the sum ${u}_{1}^{2}+{u}_{2}^{2}+\cdots +{u}_{n}^{2}$ to also be 1! How do we achieve this if $‖\stackrel{\to }{u}‖\ne 1$? We do the following:

### Orthogonal Vectors and Linear Independence

Figure 1

Orthogonal vectors are vectors that are perpendicular to each other. In a standard 2D or 3D graph, this means that they are at right angles to each other and we can visualise them as seen in Figure 1: $\stackrel{\to }{x}$ is at 90 degrees to both $\stackrel{\to }{y}$ and $\stackrel{\to }{z}$. $\stackrel{\to }{y}$ is at 90 degrees to $\stackrel{\to }{x}$ and $\stackrel{\to }{z}$, and $\stackrel{\to }{z}$ is at 90 degrees to $\stackrel{\to }{y}$ and $\stackrel{\to }{z}$.

In any set of any vectors, $\left[\stackrel{\to }{{a}_{1}},...,\stackrel{\to }{{a}_{n}}\right]$, the vectors will be linearly independent if every vector in the set is orthogonal to every other vector in the set. Note, however that whilst an orthogonal set is L.I., a L.I. set is not necessarily an orthogonal set. Take the following example: The vectors $\stackrel{\to }{a}$ and $\stackrel{\to }{b}$ are L.I. because nethier can be represented as a linear combination of the other. They are not however orthogonal.

So, how do we tell if one vector is orthogonal to another? The answer is the dot product which is defined as follows. $x\cdot y=\sum _{1}^{n}{x}_{i}{y}_{i}$

We know when two vectors are orthogonal when their dot product is zero: $x\cdot y=0\phantom{\rule{0.278em}{0ex}}⟹\phantom{\rule{0.278em}{0ex}}$ x and y are orthogonal. You can scale either or both vectors and their dot product will still be zero!

But why is this the case? Lets imagine any two arbitrary vectors, each on the circumference of a unit circle (so we know that they have the same length and are therefore a proper rotation of a vector around the center of the circle). This is shown in figure 2. From the figure, we know the following:

Figure 2

$\begin{array}{rlrl}{x}_{1}& =r\mathrm{cos}{\theta }_{1}& {y}_{1}& =r\mathrm{sin}{\theta }_{1}\\ {x}_{2}& =r\mathrm{cos}\left({\theta }_{1}+{\theta }_{n}\right)& {y}_{2}& =r\mathrm{sin}\left({\theta }_{1}+{\theta }_{n}\right)\end{array}$ The vector ${x}_{2}$ is the vector ${x}_{1}$ rotated by ${\theta }_{n}$ degrees. We can use the following trig identities: $\begin{array}{rl}\mathrm{sin}\left(a±b\right)& =\mathrm{sin}\left(a\right)\mathrm{cos}\left(b\right)±\mathrm{cos}\left(a\right)\mathrm{sin}\left(b\right)\\ \mathrm{cos}\left(a±b\right)& =\mathrm{cos}\left(a\right)\mathrm{cos}\left(b\right)\mp \mathrm{sin}\left(a\right)\mathrm{sin}\left(b\right)\end{array}$ Substitute these into the formulas above, we get the following. $\begin{array}{rl}{x}_{2}& =r\mathrm{cos}{\theta }_{1}\mathrm{cos}{\theta }_{n}-r\mathrm{sin}{\theta }_{1}\mathrm{sin}{\theta }_{n}\\ {y}_{2}& =r\mathrm{sin}{\theta }_{1}\mathrm{cos}{\theta }_{n}+r\mathrm{cos}{\theta }_{1}\mathrm{sin}{\theta }_{n}\end{array}$ Which means that... $\begin{array}{rl}{x}_{2}& ={x}_{1}\mathrm{cos}{\theta }_{n}-{y}_{1}\mathrm{sin}{\theta }_{n}\\ {y}_{2}& ={y}_{1}\mathrm{cos}{\theta }_{n}+{x}_{1}\mathrm{sin}{\theta }_{n}\end{array}$ For a 90 degree rotation ${\theta }_{n}={90}^{\circ }$ we know that $\mathrm{cos}{\theta }_{n}=0$ and $\mathrm{sin}{\theta }_{n}=1$. Substiuting these values into the above equations we can clearly see that... $\begin{array}{rl}{x}_{2}& =-{y}_{1}\\ {y}_{2}& ={x}_{1}\end{array}$ Therefore, any vector in 2D space that is $\left[a,b\right]$ will become $\left[-b,a\right]$ and therefore the dot product becomes $-ab+ab=0$. And voilà, we know know why the dot product of two orthogonal 2D vectors is zero. I'm happy to take it on faith that this extrapolates into n dimensions :)

Another way of looking at this is to consider the law of cosines: ${C}^{2}={A}^{2}+{B}^{2}-2AB\mathrm{cos}\left(c\right)$:

Here $A$ and $V$ represent the magnitude of the vectors $\stackrel{\to }{x}$, $‖\stackrel{\to }{x}‖$, and $\stackrel{\to }{y}$, $‖\stackrel{\to }{y}‖$. $C$ represents the magnitude of the vector $‖\stackrel{\to }{x}-\stackrel{\to }{y}‖$. Thus, we have this:

I.e., $‖\stackrel{\to }{x}-\stackrel{\to }{y}{‖}^{2}=‖\stackrel{\to }{x}{‖}^{2}+‖\stackrel{\to }{y}{‖}^{2}-2‖\stackrel{\to }{x}‖‖\stackrel{\to }{y}‖\mathrm{cos}\left({\theta }_{c}\right)$.

When the angle between the vectors is 90 degrees, $\mathrm{cos}\left(90\right)=0$ and so that part of the equation disappears to give us $‖\stackrel{\to }{x}-\stackrel{\to }{y}{‖}^{2}=‖\stackrel{\to }{x}{‖}^{2}+‖\stackrel{\to }{y}{‖}^{2}$. Now... $‖\stackrel{\to }{x}-\stackrel{\to }{y}{‖}^{2}=‖\stackrel{\to }{x}{‖}^{2}+‖\stackrel{\to }{y}{‖}^{2}\phantom{\rule{0ex}{0ex}}\therefore ‖\stackrel{\to }{x}{‖}^{2}+‖\stackrel{\to }{y}{‖}^{2}-‖\stackrel{\to }{x}-\stackrel{\to }{y}{‖}^{2}=0$ Recall that $‖\stackrel{\to }{v}‖=\sqrt{{v}_{1}^{2}+{v}_{2}^{2}+...+{v}_{n}^{2}}$ and that therefore $‖\stackrel{\to }{v}{‖}^{2}={v}_{1}^{2}+{v}_{2}^{2}+...+{v}_{n}^{2}$ .

Based, on this we can say that... $\begin{array}{rl}‖\stackrel{\to }{x}-\stackrel{\to }{y}{‖}^{2}& =\left({x}_{1}-{y}_{1}{\right)}^{2}+\left({x}_{2}-{y}_{2}{\right)}^{2}+...+\left({x}_{n}-{y}_{n}{\right)}^{2}\\ & ={x}_{1}^{2}-2{x}_{1}{y}_{1}+{y}_{1}^{2}+{x}_{2}^{2}-2{x}_{2}{y}_{2}+{y}_{2}^{2}+...+{x}_{n}^{2}-2{x}_{n}{y}_{n}+{y}_{n}^{2}\end{array}$ Now, all of the ${x}_{i}^{2}$ and ${y}_{i}^{2}$ terms above will be cancelled out by the $‖\stackrel{\to }{x}{‖}^{2}$ and $‖\stackrel{\to }{y}{‖}^{2}$ terms, leaving us with... $‖\stackrel{\to }{x}{‖}^{2}+‖\stackrel{\to }{y}{‖}^{2}-‖\stackrel{\to }{x}-\stackrel{\to }{y}{‖}^{2}=2{x}_{1}{y}_{1}+2{x}_{2}{y}_{2}+...+2{x}_{n}{y}_{n}=0$ Which is just twice the dot product when the vectors are at 90 degrees - or just the dot product because we can divide through by 2.

## Matrices

### Properties

Khan Academy has great articles. This is another good reference from MIT.

#### Scalar Multiplication

1. Associative: $\left(cd\right)A=c\left(dA\right)$
2. Distributive: $c\left(A+B\right)=cA+cB$ and $\left(c+d\right)A=cA+dA$
3. Identity: $1A=A$
4. Zero: $0A=O$
5. Closure: $cA$ is a matrix of the same dimensions as $A$.

Note that scalar multiplication is not commutative: $cA\ne Ac$!

1. Commutative: $A+B=B+A$
2. Associative: $A+\left(B+C\right)=\left(A+B\right)+C$
3. Zero: For any matrix $A$, there is a unique matrix $O$ such that $A+O=A$
4. Inverse:
5. Closure: $A+B$, is a matrix of the same dimensions as $A$ and $B$.

#### Matrix Multiplication

1. Associative: $\left(AB\right)C=A\left(BC\right)$
2. Distributive: $A\left(B+C\right)=AB+AC$
3. Identity: $IA=A$
4. Zero: $OA=O$
5. Inverse: Only if $A$ is a square matrix, then ${A}^{-1}$ is its inverse and $A{A}^{-1}={A}^{-1}A=I$. Note that not all matrices are invertible.
6. Dimension: If $A$ is an $m×n$ matrix and $B$ is an $n×k$ matrix then $AB$ is an $m×k$ matrix.

Note that matrix multiplication is not commutative: $AB\ne BA$!

Be careful: the equation $AB=0$ does not necessarily mean that $A=0$ or $B=0$ and for a general matrix $A$, $AB=AC⇏B=C$, unless $A$ is invertible.

#### Matrix Transpose

1. Associative:$\left(rA{\right)}^{T}=r{A}^{T},r\in \mathbb{R}$
2. Distributive (into addition): $\left(A+B{\right)}^{T}={A}^{T}+{B}^{T}$
3. Distributive (into mult):
Generalises to $\left(ABC{\right)}^{T}={C}^{T}{B}^{T}{A}^{T}$
4. Identity: ${I}^{T}=I$
5. Inverse: $\left({A}^{T}{\right)}^{T}=A$
6. Name?: $\left({A}^{T}{\right)}^{-1}=\left({A}^{-1}{\right)}^{T}$
7. Name?:
8. Name?: $\mathrm{rank}\left(A\right)=\mathrm{rank}\left({A}^{T}\right)$
9. If columns of $A$ are LI then columns of ${A}^{T}A$ are LI. ${A}^{T}A$ is square and also invertible.

#### Matrix Inverse

1. Associative (self with inverse): $A{A}^{-1}={A}^{-1}A=I$
2. Distributive (into scalar mult):
3. Distributive (into mult):
4. Identity: ${I}^{-1}=I$
5. Name?: $\left({A}^{-1}{\right)}^{-1}=A$
6. Name?: $\left({A}^{T}{\right)}^{-1}=\left({A}^{-1}{\right)}^{T}$

### Matricies, Simultaneous Linear Equations And Reduced Row Echelon Form

References:

The set of linear equations: ${a}_{11}{x}_{1}+{a}_{12}{x}_{2}+...+{a}_{1n}{x}_{n}={b}_{1}$ ${a}_{21}{x}_{1}+{a}_{22}{x}_{2}+...+{a}_{2n}{x}_{n}={b}_{2}$ $...$ ${a}_{m1}{x}_{1}+{a}_{m2}{x}_{2}+...+{a}_{mn}{x}_{n}={b}_{m}$ Can be represented in matrix form: $\left[\begin{array}{cccc}{a}_{11}& {a}_{12}& \cdots & {a}_{1n}\\ {a}_{21}& {a}_{22}& \cdots & {a}_{2n}\\ ⋮& ⋮& \ddots & ⋮\\ {a}_{m1}& {a}_{m2}& \cdots & {a}_{mn}\end{array}\right]\left[\begin{array}{c}{x}_{1}\\ {x}_{2}\\ ⋮\\ {x}_{n}\end{array}\right]=\left[\begin{array}{c}{b}_{1}\\ {b}_{2}\\ ⋮\\ {b}_{m}\end{array}\right]$ Any vector $\stackrel{\to }{x}$, where $A\stackrel{\to }{x}=\stackrel{\to }{b}$, is a solution to the set of simultaneous linear equations. How can we solve this from the matrix. We create an augmented or patitioned matrix: $\left[\begin{array}{ccccc}1{a}_{11}& {a}_{12}& \cdots & {a}_{1n}& {b}_{1}\\ {a}_{21}& {a}_{22}& \cdots & {a}_{2n}& {b}_{2}\\ ⋮& ⋮& \ddots & ⋮& ⋮\\ {a}_{m1}& {a}_{m2}& \cdots & {a}_{mn}& {b}_{m}\end{array}\right]$ Next this matrix must be converted to row echelon form. This is where each row has the same or less zeros to the left than the row below. For example, the following matrix is in row echelon form: $\left[\begin{array}{cccc}1& 2& 3& 4\\ 0& 1& 2& 3\\ 0& 0& 0& 1\\ 0& 0& 0& 2\end{array}\right]$ But, this next one is not: $\left[\begin{array}{cccc}1& 2& 3& 4\\ 0& 0& 0& 1\\ 0& 0& 0& 2\\ 0& 1& 2& 3\end{array}\right]$ We go from a matrix to the equivalent in row-echelon form using elementary row operations:

1. Row interchange: ${R}_{i}↔{R}_{j}$
2. Row scaling: ${R}_{i}\to k{R}_{i}$
3. Row addition: ${R}_{i}\to {R}_{i}+k{R}_{j}$

In row echelon form:

1. All rows containing only zeros appear below rows with nonzero entries, and
2. The first nonzero entry in any row appears in a column to the right of the first nonzero entry in any preceding row.

The first non zero entry in a row is called the pivot for that row.

And woop, woop, even more important than echelon form is reduced row-echelon form (rref). This is when:

1. If a row has all zeros then it is below all rows with a non-zero entry.
2. The left most entry in each row is 1 - it is called the pivot.
3. The left most non-zero entry in each row is the only non-zero in that column.
4. Each row has more zeros to the left of the pivot than the row above.

Or, to put it another way, when it is a matrix in row-echelon form where:

1. All pivots are equal to 1, and
2. Each pivot is the only non-zero in its column.

Some important terms are pivot position and pivot column. The position is the location of a leading 1, which meets the above criteria, and the column is a column that contains a pivot position.

So why do we give a damn above RREF if we have row-echelon form? Well, one reason is it lets us figure out if a set of linear equations has a solution and which variables are free and which are dependent. The reason for this is that the RREF of every matrix is unique (whereas merely row reducing a matrix can have many resulting forms).

The free variable is one that you have control over, i.e. you can choose and manipulate its value. The dependent one depends on the values of the other variables in the experiment or is constant.

Pivot columns represent variables that are dependent. Why? Recall that the column vector containing a pivot is all-zeros except for the pivot. So if element j in a row of a rref matrix is a pivot, then in our system of equations ${x}_{j}$ only appears in this one equations in our RREF matrix. Thus, its value must be determined as this is the only place it occurs. It must either be a constant or a combination of other variables.

Because column vectors containing a pivot are all-zeros except for the pivot, the set of pivot columns must also be LI (see later). You can always represent the free columns as linear combinations of the pivot columns.

If we have an augmented matrix $\left[A|b\right]$:

1. No Solution. If the last (augmented) column of $\left[A|b\right]$ (ie. the column which contains $b$) contains a pivot entry.
2. Restructed Solution Set. If the last row of the matrix is all zeros except the pivot column which is a function of ${b}_{1}\dots {b}_{m}$.
3. Exactly One Solution. If the last (augmented) column of $\left[A|b\right]$ (ie. the column which contains $b$) does not contain a pivot entry and all of the columns of the coefficient part (ie. the columns of $A$) do contain a pivot entry.
4. Infinitely Many Solutions. If the last (augmented) column of $\left[A|b\right]$ (ie. the column which contains $b$) does not contain a pivot entry and at least one of the columns of the coefficient part (ie. the columns of $A$) also does not contain a pivot entry.

Let's look at a quick example of a matrix in echelon-form: $\left[\begin{array}{cccc}-5& -1& -3& 3\\ 0& 3& 5& 8\\ 0& 0& 2& -4\end{array}\right]$

We can get the solution to the set of simultaneous linear equations using back substitution. Directly from the above row-echelon form (useful because the last row has one pivot and no free variables) matrix we know that: $\begin{array}{}\text{(1)}& -5{x}_{1}-{x}_{2}-3X3=3\end{array}$ $\begin{array}{}\text{(2)}& 3{x}_{2}+5{x}_{3}=8\end{array}$ $\begin{array}{}\text{(3)}& 2{x}_{3}=-4\end{array}$ From (1) we know: $\begin{array}{}\text{(4)}& {x}_{3}=-2\end{array}$ Substitute (4) back into (2): $\begin{array}{}\text{(5)}& 3{x}_{2}+-10=8\phantom{\rule{0.278em}{0ex}}⟹\phantom{\rule{0.278em}{0ex}}{x}_{2}=6\end{array}$ Substitute (5) and (4) back into (1): $\begin{array}{}\text{(6)}& -5{x}_{1}-6+6=3\phantom{\rule{0.278em}{0ex}}⟹\phantom{\rule{0.278em}{0ex}}{x}_{1}=-\frac{3}{5}\end{array}$

We can use RREF to accomplish the same thing and find the solutions to the above. $\left[\begin{array}{cccc}-5& -1& -3& 3\\ 0& 3& 5& 8\\ 0& 0& 2& -4\end{array}\right]$ $\to \left[\begin{array}{cccc}1& \frac{1}{5}& -\frac{3}{5}& -\frac{3}{5}\\ 0& 3& 5& 8\\ 0& 0& 1& -2\end{array}\right]\left(r1=\frac{r1}{5},r3=\frac{r3}{2}\right)$ $\to \left[\begin{array}{cccc}1& \frac{1}{5}& -\frac{3}{5}& -\frac{3}{5}\\ 0& 3& 0& 18\\ 0& 0& 1& -2\end{array}\right]\left(r2=r2-5r3\right)$ $\to \left[\begin{array}{cccc}1& \frac{1}{5}& -\frac{3}{5}& -\frac{3}{5}\\ 0& 1& 0& 6\\ 0& 0& 1& -2\end{array}\right]\left(r2=\frac{r2}{3}\right)$ $\to \left[\begin{array}{cccc}1& 0& 0& -\frac{3}{5}\\ 0& 1& 0& 6\\ 0& 0& 1& -2\end{array}\right]\left(r1=r1+\frac{3r3}{5}\to ,r1=r1-\frac{r2}{5}\right)$ Which means we come to the same conclusion as we did when doing back substitution, but were able to do it using elementary row operations.

We can not talk about the general solution vector, $\stackrel{\to }{x}$, which in this case is: $\left[\begin{array}{c}{x}_{1}\\ {x}_{2}\\ {x}_{3}\end{array}\right]=\left[\begin{array}{c}-\frac{3}{5}\\ 6\\ -2\end{array}\right]$ We can also talk about the solution set, which is the set of all vectors that result in a valid solution to our system of equations. In this case our solution set is trivial: it just has the above vector in it because the RREF had pivots in every column so there is exactly one solution.

Lets, therefore, look at something more interesting. Take the RREF matrix below: $\left[\begin{array}{ccccc}1& 0& 4& 9& 0\\ 0& 1& 8& 3& 0\\ 0& 0& 0& 0& 0\\ 0& 0& 0& 0& 0\end{array}\right]$ Now we have two free variables! Now ${x}_{3}=a$ and ${x}_{4}=b$ where $a$ and $b$ can be any values we like. Now the general solution vector looks like this: $\left[\begin{array}{c}{x}_{1}\\ {x}_{2}\\ {x}_{3}\\ {x}_{4}\end{array}\right]=\left[\begin{array}{c}-4a-9b\\ -8a-3b\\ a\\ b\end{array}\right]$ How did we get here? We we know from the RREF matrix that: ${x}_{1}+4{x}_{3}a+9{x}_{4}b=0$ ${x}_{2}+8{x}_{3}a+3{x}_{4}b=0$ We replace ${x}_{3}$ and ${x}_{4}$ with our free variables and then solve for the pivots, thus getting the general solution vector.

The above can then be represented using the general solution vector: $\left[\begin{array}{c}-4a-9b\\ -8a-3b\\ a\\ b\end{array}\right]=a\left[\begin{array}{c}-4\\ -8\\ 1\\ 0\end{array}\right]+b\left[\begin{array}{c}-9b\\ -3b\\ 0\\ 1\end{array}\right]$ The solution set thus becomes: $\mathrm{span}\left(\left[\begin{array}{c}-4\\ -8\\ 1\\ 0\end{array}\right],\left[\begin{array}{c}-9\\ -3\\ 0\\ 1\end{array}\right]\right)$

We can find the reduced row echelon form of a matrix in python using the sympy package and the rref() function:

from sympy import Matrix, init_printing

init_printing(use_unicode=True)

system = Matrix(( (3, 6, -2, 11), (1, 2, 1, 32), (1, -1, 1, 1) ))
system
system.rref()[0]

Which outputs:

⎡1  0  0  -17/3⎤
⎢              ⎥
⎢0  1  0  31/3 ⎥
⎢              ⎥
⎣0  0  1   17  ⎦

To then apply this to our augmented matrix we could do something like the following. Lets say we have a set of 3 simultaneous equations with 3 unknowns: $3x+6y-2z=11\phantom{\rule{0ex}{0ex}}x+2y+z=32\phantom{\rule{0ex}{0ex}}x-y+z=1$ We'd make an augmented matrix like so: $\left[\begin{array}{cccc}3& 6& -2& 11\\ 1& 2& 1& 32\\ 1& -1& 1& 1\end{array}\right]$ To solve this using Python we do:

from sympy import Matrix, solve_linear_system, init_printing
from sympy.abc import x, y, z

init_printing(use_unicode=True)

system = Matrix(( (3, 6, -2, 11), (1, 2, 1, 32), (1, -1, 1, 1) ))
system

solve_linear_system(system, x, y, z)

Which will give the following output:

⎡3  6   -2  11⎤
⎢             ⎥
⎢1  2   1   32⎥
⎢             ⎥
⎣1  -1  1   1 ⎦
{x: -17/3, y: 31/3, z: 17}

### Matrix / Vector Multiplication

Matrix/vector multiplication is pretty straight forward: $\left[\begin{array}{cc}a& c\\ b& d\end{array}\right]\left[\begin{array}{c}2\\ 4\end{array}\right]=\left[\begin{array}{c}2a+4c\\ 2b+4d\end{array}\right]$

The concept of matrix multiplication, the type I learnt in school, is shown in the little animation below. For each row vector of the LHS matrix we take the dot product of that vector with each column vector from the RHS matrix to produce the result:

But having said that, I'd never really thought of it as shown below until watching some stuff on Khan Academy:

$\left[\begin{array}{cc}a& c\\ b& d\end{array}\right]\left[\begin{array}{c}2\\ 4\end{array}\right]=2\left[\begin{array}{c}a\\ b\end{array}\right]+4\left[\begin{array}{c}c\\ d\end{array}\right]$

We can think of it as the linear combination of the column vectors of the matrix where the coefficients are the members of the vector, where the first column vector is multiplied by the first element, the second column vector by the second element and so on.

So, for any mxn matrix, $A$, and vector $\stackrel{\to }{v}\in {\mathbb{R}}^{n}$ we can say that, $A\stackrel{\to }{v}=\left[\begin{array}{cccc}↑& ↑& & ↑\\ ⋮& ⋮& & ⋮\\ \stackrel{\to }{{c}_{1}}& \stackrel{\to }{{c}_{2}}& \cdots & \stackrel{\to }{{c}_{n}}\\ ⋮& ⋮& & ⋮\\ ↓& ↓& & ↓\end{array}\right]\left[\begin{array}{c}{v}_{1}\\ {v}_{2}\\ ⋮\\ {v}_{n}\end{array}\right]={v}_{1}\stackrel{\to }{{c}_{1}}+{v}_{2}\stackrel{\to }{{c}_{2}}+\cdots +{v}_{n}\stackrel{\to }{{c}_{n}}$

### Null Space Of A Matrix

#### Definition

For an nxm vector $A$, the nullspace of the nxm matrix $A$, $N\left(A\right)$ is defined as follows: $N\left(A\right)=\left\{\stackrel{\to }{x}\in {\mathbb{R}}^{m}\mid A\stackrel{\to }{x}=\stackrel{\to }{0}\right\}$ In words, the null space of a matrix is the set of all solutions that result in the zero vector, i.e. the solution set to the above. We can get this set by using the normal reduction to RREF to solve the above ($\left[A\mid \stackrel{\to }{0}\right]⟶\left[R\mid \stackrel{\to }{0}\right]$). The solution space set to this is the null space.

The system of linear equations $A\stackrel{\to }{x}=\stackrel{\to }{0}$ is called homogeneous. It is always consistent, i.e., has a solution, because $\stackrel{\to }{x}=\stackrel{\to }{0}$ is always a solution (and is called the trivial solution).

The null space of a matrix is a valid subspace of ${\mathbb{R}}^{n}$ because it satisfies the following conditions, as we saw in the section on subspaces.

1. $N\left(A\right)$ contains the zero vector: $\stackrel{\to }{0}\in N\left(A\right)$
2. $N\left(A\right)$ is closed under scalar multiplication: $\stackrel{\to }{x}\in N\left(A\right),\alpha \in \mathbb{R}\phantom{\rule{0.278em}{0ex}}⟹\phantom{\rule{0.278em}{0ex}}\alpha \stackrel{\to }{x}\in N\left(A\right)$
3. $N\left(A\right)$ is closed under addition: $\stackrel{\to }{a}\in N\left(A\right),\stackrel{\to }{b}\in N\left(A\right)\phantom{\rule{0.278em}{0ex}}⟹\phantom{\rule{0.278em}{0ex}}\stackrel{\to }{a}+\stackrel{\to }{b}\in N\left(A\right)$

It can also be shown that $N\left(A\right)=N\left(\mathrm{RREF}\left(A\right)\right)$, where $\mathrm{RREF}$ is the reduced row echelon form.

#### Relation To L.I. Of Column Vectors

The nullspace of a matrix can be related to the linear independence of it's column vectors. Using the above definition of nullspace, we can write: $A\stackrel{\to }{v}=\left[\begin{array}{cccc}↑& ↑& & ↑\\ ⋮& ⋮& & ⋮\\ \stackrel{\to }{{a}_{1}}& \stackrel{\to }{{a}_{2}}& \cdots & \stackrel{\to }{{a}_{n}}\\ ⋮& ⋮& & ⋮\\ ↓& ↓& & ↓\end{array}\right]\left[\begin{array}{c}{x}_{1}\\ {x}_{2}\\ ⋮\\ {x}_{n}\end{array}\right]=\left[\begin{array}{c}{0}_{1}\\ {0}_{2}\\ ⋮\\ {0}_{m}\end{array}\right]$ Recalling how we can write out vector/scalar multipication, we get, ${x}_{1}\stackrel{\to }{{a}_{1}}+{x}_{2}\stackrel{\to }{{a}_{2}}+\cdots +{x}_{n}\stackrel{\to }{{a}_{n}}=\stackrel{\to }{0}$ Recall from the section on linear independence that the above set of vectors is said to be linearly dependent when: Given that our nullspace is the set of all vectors that satisfy the above, by definition, then we can say that the column vectors of a matrix A are LI if and only if $N\left(A\right)=\stackrel{\to }{0}$.

#### Relation To Determinant

If the determinant of a matrix is zero then the null space will be non trivial.

#### Calculating The Null Space

To find the null space of a matrix $A$, augment it with the zero vector and convert it to RREF. Then the solution set is the null space. So, if there are only pivots, the null space only contains the zero vector because there is only one solution (which therefore must be 0).

##### Example #1

Let's look at a trivial example: Then the null space is defined as the solution set to $A\stackrel{\to }{x}=\stackrel{\to }{0}$, i.e... $\left[\begin{array}{ccc}4& 1& 1\\ 8& 3& 0\\ 0& 0& 3\end{array}\right]\left[\begin{array}{c}{x}_{1}\\ {x}_{2}\\ {x}_{3}\end{array}\right]=\left[\begin{array}{c}0\\ 0\\ 0\end{array}\right]$ We find the solution set using the normal augmented matrix method: $\left[\begin{array}{cccc}4& 1& 1& 0\\ 8& 3& 0& 0\\ 0& 0& 3& 0\end{array}\right]↦\left[\begin{array}{cccc}4& 1& 1& 0\\ 0& 1& -1& 0\\ 0& 0& 3& 0\end{array}\right]↦\left[\begin{array}{cccc}4& 1& 1& 0\\ 0& 1& -1& 0\\ 0& 0& 1& 0\end{array}\right]\phantom{\rule{0ex}{0ex}}↦\left[\begin{array}{cccc}4& 1& 0& 0\\ 0& 1& 0& 0\\ 0& 0& 1& 0\end{array}\right]↦\left[\begin{array}{cccc}1& 0& 0& 0\\ 0& 1& 0& 0\\ 0& 0& 1& 0\end{array}\right]$ There are no free variables, so therefore the solution set can contain only the zero vector because we have three contraints ${x}_{1}=0,{x}_{2}=0$ and ${x}_{3}=0$. The only values for the ${x}_{i}$'s that can satisfy these constrains is zero, hence the null space can only contain the zero vector.

##### Example #2

Lets try an consider another trivial example. It's pretty contrived because I constructed it by applying row operations to the identify matrix! Null space is defined as solutions to: $\left[\begin{array}{ccc}2& 3& 0\\ 6& 12& 0\\ 8& 15& 0\end{array}\right]\left[\begin{array}{c}{x}_{1}\\ {x}_{2}\\ {x}_{3}\end{array}\right]=\left[\begin{array}{c}0\\ 0\\ 0\end{array}\right]$ We find the solution set using the normal augmented matrix method: $\left[\begin{array}{cccc}2& 3& 0& 0\\ 6& 12& 0& 0\\ 8& 15& 0& 0\end{array}\right]↦\left[\begin{array}{cccc}1& 0& 0& 0\\ 0& 1& 0& 0\\ 0& 0& 0& 0\end{array}\right]$ Now we can see that ${x}_{1}=0$ and ${x}_{2}=0$. The variable ${x}_{3}$, however, is free. It can take any value. Let's call that value ${x}_{3}=a$. The solution vector is therefore: $\left[\begin{array}{c}{x}_{1}\\ {x}_{2}\\ {x}_{3}\end{array}\right]=\left[\begin{array}{c}0\\ 0\\ a\end{array}\right]$ The general solution vectors is therefore: $a\left[\begin{array}{c}0\\ 0\\ 1\end{array}\right]$ So we can say the null space is: $\mathrm{N}\left(A\right)=\mathrm{span}\left(\left[\begin{array}{c}0\\ 0\\ 1\end{array}\right]\right)$

##### Example #3

Let's try one more example. This one is right out of Khan Achademy rather then my own made up rubbish :) We calculate the null space by setting up an augmented matrix to solve for $A\stackrel{\to }{x}=\stackrel{\to }{0}$: $\left[\begin{array}{cccc}2& -1& -3& 0\\ -4& 2& 6& 0\end{array}\right]↦\left[\begin{array}{cccc}1& -1/2& -3/2& 0\\ 0& 0& 0& 0\end{array}\right]$ We thus know that: ${x}_{1}=\frac{1}{2}{x}_{2}+\frac{3}{2}{x}_{3}$ And that ${x}_{2}$ and ${x}_{3}$ are free variables. This means that the general solution is: $\left[\begin{array}{c}{x}_{1}\\ {x}_{2}\\ {x}_{3}\end{array}\right]={x}_{2}\left[\begin{array}{c}\frac{1}{2}\\ 1\\ 0\end{array}\right]+{x}_{3}\left[\begin{array}{c}\frac{3}{2}\\ 0\\ 1\end{array}\right]$ And therefore we can define the null space as: $\mathrm{N}\left(A\right)=\mathrm{span}\left(\left[\begin{array}{c}\frac{1}{2}\\ 1\\ 0\end{array}\right],\left[\begin{array}{c}\frac{3}{2}\\ 0\\ 1\end{array}\right]\right)$

#### An Intuitive Meaning

This StackOverflow thread gives some really good intuitive meaning to the null space. I've quoted some of the answers verbatim here:

It's good to think of the matrix as a linear transformation; if you let $h\left(\stackrel{\to }{v}\right)=A\cdot \stackrel{\to }{v}$, then the null-space is ... the set of all vectors that are sent to the zero vector by $h$. Think of this as the set of vectors thatlose their identity as $h$ is applied to them.

Let's suppose that the matrix A represents a physical system. As an example, let's assume our system is a rocket, and A is a matrix representing the directions we can go based on our thrusters. So what do the null space and the column space represent?

Well let's suppose we have a direction that we're interested in. Is it in our column space? If so, then we can move in that direction. The column space is the set of directions that we can achieve based on our thrusters. Let's suppose that we have three thrusters equally spaced around our rocket. If they're all perfectly functional then we can move in any direction. In this case our column space is the entire range. But what happens when a thruster breaks? Now we've only got two thrusters. Our linear system will have changed (the matrix A will be different), and our column space will be reduced.

What's the null space? The null space are the set of thruster intructions that completely waste fuel. They're the set of instructions where our thrusters will thrust, but the direction will not be changed at all.

Another example: Perhaps A can represent a rate of return on investments. The range are all the rates of return that are achievable. The null space are all the investments that can be made that wouldn't change the rate of return at all.

#### Nullity Of A Matrix

The dimension of a subspace is the number of elements in a basis for that subspace. The dimension of the null space is called the "nullity":

In the null space you will always have as many vectors as you have free variables in the RREF of the matrix. So the nullity is the number of free variables in the RREF of the matrix with which this null space is associated: This the null space has dimension, or nullity, $n-\mathrm{rank}\left(A\right)$. This equates to the number of free variables.

### Column Space Of A Matrix

The columns space of a matrix is the set of all linear combinations of its column vectors, which is the span of the column vectors: Note that the column vectors of $A$ might not be LI. The set can be reduced so that only the LI vectors are used, which means the above still holds, and then we say that the LI set is a basis for $\mathrm{C}\left(A\right)$. The column space of A is a valid subspace.

For the system of equations $A\stackrel{\to }{x}=\stackrel{\to }{b}$, $\mathrm{C}\left(A\right)$ is the set of all values that $A\stackrel{\to }{x}$ can be. We can look at this this way: $A\stackrel{\to }{x}=\left[\begin{array}{cc}a& b\\ c& d\end{array}\right]\left[\begin{array}{c}x\\ y\end{array}\right]=\left[\begin{array}{c}ax+by\\ cx+dy\end{array}\right]=x\left[\begin{array}{c}a\\ c\end{array}\right]+y\left[\begin{array}{c}b\\ d\end{array}\right]=\stackrel{\to }{b}$ The solution, $\stackrel{\to }{b}$, can be seen to be a linear combination of the column vectors of $A$. Thus, $\stackrel{\to }{b}\in \mathrm{C}\left(A\right)$.

Therefore, if $A\stackrel{\to }{x}=\stackrel{\to }{{b}_{1}}$ and $\stackrel{\to }{{b}_{1}}\notin \mathrm{C}\left(A\right)$, then we know that no solution exists, a conversely, if it is then we know that at least one solution exists.

The set of vectors in the column space of may or may not be linearly independent. When reduced to being LI then we have a basis for the column space of the matrix.

We saw the following in the section of null spaces: It can be shown that the column vectors of a matrix $A$ are LI if and only if $N\left(A\right)=\stackrel{\to }{0}$. So we can figure out if we have a basis by looking at $A$'s null space. Recall that $\mathrm{N}\left(A\right)=\mathrm{N}\left(\mathrm{RREF}\left(A\right)\right)$ and that the column vectors of a matrix A are LI if and only if $N\left(A\right)=\stackrel{\to }{0}$!

How do we figure out the set of column vectors that are LI? To do this, put the matrix in RREF and select the columns that have pivot entries (the pivot columns). The pivot column vectors are the basis vectors for $\mathrm{C}\left(A\right)$ :) The reason is that you can always write the columns with the free variables as linear combinations of the pivot columns.

Because column vectors containing a pivot are all-zeros except for the pivot, the set of pivot columns must also be LI. You can always represent the free columns as linear combinations of the pivot columns.

So to find column space of $A$, pick the columns from $A$ that correspond to (have the same position as) the pivot columns in $\mathrm{RREF}\left(A\right)$.

A really interested property of the column space is the column space criterion which states that a linear system, $A\stackrel{\to }{x}=\stackrel{\to }{b}$ has a solution iff $\stackrel{\to }{b}$ is in the column space of A.

### Rank Of A Matrix

We can now define what the rank of a matrix is: I.e., The rank of a matrix is the number of pivots. This also means that the rank is the number of vectors in a basis for the column space of $A$. You can get this by counting the pivot columns in $\mathrm{RREF}\left(A\right)$.

The rank equation is $\mathrm{rank}\left(A\right)+\mathrm{nullity}\left(A\right)=n$, where $A$ is an $mxn$ matrix.

If $A$ is reduced to row-echelon form $H$, then:

1. $\mathrm{nullity}\left(A\right)$ is the number of free variables in solution space of $A\stackrel{\to }{x}=\stackrel{\to }{0}$, which equals the number of pivot-free columns in $H$.
2. $\mathrm{rank}\left(A\right)$ is the number of pivots in $H$.
3. $\mathrm{rank}\left(A\right)+\mathrm{nullity}\left(A\right)=n$, equals the number of columns of $A$.
TODO:
https://math.stackexchange.com/questions/21100/importance-of-matrix-rank


### Basis Of The Column Space VS Basis Of The Null Space

... a "basis of a column space" is different than a "basis of the null space", for the same matrix....

A basis is a a set of vectors related to a particular mathematical "space" (specifically, to what is known as a vector space). A basis must:

1. be linearly independent and
2. span the space.

The "space" could be, for example: ${\mathbb{R}}^{2}$, ${\mathbb{R}}^{3}$, ${\mathbb{R}}^{4}$, ... , the column space of a matrix, the null space of a matrix, a subspace of any of these, and so on...

### Orthogonal Matrices

So, onto orthogonal matrices. A matrix is orthogonal if $A{A}^{T}={A}^{T}A=I$. If we take a general matrix and multiply it by it's transpose we get...

$A{A}^{T}=\left(\begin{array}{cc}a& c\\ b& d\end{array}\right)\left(\begin{array}{cc}a& b\\ c& d\end{array}\right)=\left(\begin{array}{cc}aa+cc& ab+cd\\ ab+cd& bb+dd\end{array}\right)=\left(\begin{array}{cc}1& 0\\ 0& 1\end{array}\right)$

The pattern $ab+cd$ looks pretty familiar right?! It looks a lot like ${x}_{1}{x}_{2}+{y}_{1}{y}_{2}$, our formula for the dot product of two vectors. So, when we say $a={x}_{1}$, $b={x}_{2}$, $c={y}_{1}$ and $d={y}_{2}$, we will get the following: a matrix of two row vectors ${\stackrel{\to }{v}}_{1}=\left[{x}_{1},{y}_{1}\right]$, ${\stackrel{\to }{v}}_{2}=\left[{x}_{2},{y}_{2}\right]$. $A=\left(\begin{array}{c}{\stackrel{\to }{v}}_{1}\\ {\stackrel{\to }{v}}_{2}\end{array}\right)=\left(\begin{array}{cc}{x}_{1}& {y}_{1}\\ {x}_{2}& {y}_{2}\end{array}\right)$ $\therefore A{A}^{T}=\left(\begin{array}{cc}{x}_{1}& {y}_{1}\\ {x}_{2}& {y}_{2}\end{array}\right)\left(\begin{array}{cc}{x}_{1}& {x}_{2}\\ {y}_{1}& {y}_{2}\end{array}\right)=\left(\begin{array}{cc}{x}_{1}^{2}+{y}_{1}^{2}& {x}_{1}{x}_{2}+{y}_{1}{y}_{2}\\ {x}_{1}{x}_{2}+{y}_{1}{y}_{2}& {x}_{2}^{2}+{y}_{2}^{2}\end{array}\right)$ If our vectors ${\stackrel{\to }{v}}_{1}$ and ${\stackrel{\to }{v}}_{2}$ are orthogonal, then the component ${x}_{1}{x}_{2}+{y}_{1}{y}_{2}$ must be zero. This would give us the first part of the identify matrix pattern we're looking for.

The other part of the identity matrix would imply that we would have to have ${x}_{1}^{2}+{y}_{1}^{2}=1$ and ${x}_{2}^{2}+{y}_{2}^{2}=1$... which are just the formulas for the square of the length of a vector. Therefore, if our two vectors are normal (i.e, have a length of 1), we have our identity matrix.

Does the same hold true for ${A}^{T}A$? It doesn't if we use our original matrix A!... ${A}^{T}A=\left(\begin{array}{cc}{x}_{1}& {x}_{2}\\ {y}_{1}& {y}_{2}\end{array}\right)\left(\begin{array}{cc}{x}_{1}& {y}_{1}\\ {x}_{2}& {y}_{2}\end{array}\right)=\left(\begin{array}{cc}{x}_{1}^{2}+{x}_{2}^{2}& {x}_{1}{y}_{1}+{x}_{2}{y}_{2}\\ {x}_{1}{y}_{1}+{x}_{2}{y}_{2}& {y}_{1}^{2}+{y}_{2}^{2}\end{array}\right)$ Oops, we can see that we didn't get the identity matrix!! But, perhaps we can see why. If $A$ was a matrix of row vectors then ${A}^{T}$ is a matrix of column vectors. So for $A{A}^{T}$ we were multiplying a matrix of row vectors with a matrix of column vectors, which would, in part, give us the dot products as we saw. So if we want to do ${A}^{T}A$ it would follow that for this to work $A$ now was to be a matrix of column vectors because we get back to our original (${A}^{T}$ would become a mtrix of row vectors): ${A}^{T}A=\left(\begin{array}{cc}{x}_{1}& {y}_{1}\\ {x}_{2}& {y}_{2}\end{array}\right)\left(\begin{array}{cc}{x}_{1}& {x}_{2}\\ {y}_{1}& {y}_{2}\end{array}\right)=\left(\begin{array}{cc}{x}_{1}^{2}+{y}_{1}^{2}& {x}_{1}{x}_{2}+{y}_{1}{y}_{2}\\ {x}_{1}{x}_{2}+{y}_{1}{y}_{2}& {x}_{2}^{2}+{y}_{2}^{2}\end{array}\right)$

So we can say that if we have matrix who's rows are orthogonal vectors and who's columns are also orthogonal vectors, then we have an orthogonal matrix!

Okay, thats great n' all, but why should we care? Why Are orthogonal matricies useful?. It turns our that orthogonal matricies preserve angles and lengths of vectors. This can be useful in graphics to rotate vectors but keep the shape they construct, or in numerical analysis because they do not amplify errors.

### Determinants

#### The Fundamentals

If $B$ is defined as follows... $B=\left[\begin{array}{cc}a& b\\ c& d\end{array}\right]$ Then we write the determinate of B as... $\mathrm{det}\left(B\right)=|B|=|\begin{array}{cc}a& b\\ c& d\end{array}|=ad-bc$

A matrix is invertible iff $|B|\ne 0$. We can define the inverse as follows using the determinant: ${B}^{-1}=\frac{1}{|B|}\left[\begin{array}{cc}d& -b\\ -c& a\end{array}\right]$ It is defined as long as $|B|\ne 0$.

If $A$ is a 3x3 matrix defined as follows, where the elements ${a}_{ij}$ represents the element at row $i$ and column $j$: $A=\left[\begin{array}{ccc}{a}_{11}& {a}_{12}& {a}_{13}\\ {a}_{21}& {a}_{22}& {a}_{23}\\ {a}_{31}& {a}_{32}& {a}_{33}\end{array}\right]$ We can define the determinant as: $\mathrm{det}\left(A\right)={a}_{11}|\begin{array}{cc}{a}_{22}& {a}_{23}\\ {a}_{32}& {a}_{33}\end{array}|-{a}_{12}|\begin{array}{cc}{a}_{21}& {a}_{23}\\ {a}_{31}& {a}_{33}\end{array}|+{a}_{13}|\begin{array}{cc}{a}_{21}& {a}_{22}\\ {a}_{31}& {a}_{32}\end{array}|$ Same rule applies: If the determinant is not zero then the matrix will be invertible.

We've used the first row (${a}_{11},{a}_{12},{a}_{13}$) but we could have used any row, or any column: choose the one with the most zeros as this will make the calculation easier/faster.

Select the row or column with the most zeros and go through it. Use each element ${a}_{ij}$ multiplied by the determinant of the 2x2 matrix you get if you take out the ith row and jth column of the matrix.

This generalises to an nxn matrix as follows: Define ${A}_{ij}$ to be the (n-1) x (n-1) matrix you get when you ignore the ith and jth column of the nxn matrix A.

Then we can define the determinant recursively as follows: $\text{det}\left(A\right)={a}_{11}|{A}_{11}|-{a}_{12}|{A}_{12}|+{a}_{13}|{A}_{13}|-\cdots +{a}_{1n}|{A}_{1n}|$ For each $|{A}_{ij}|$, apply the formula recursively until a 2x2 matrix is reached, at which point you can use the 2x2 determinant formula.

There is a pattern to the "+"'s and "-"'s: $\text{sign}\left(i,j\right)=-{1}^{\left(i+j\right)}$

A quick example. $A$ is defined as follows: $A=\left[\begin{array}{cccc}1& 2& 3& 4\\ 1& 0& 2& 0\\ 0& 1& 2& 3\\ 2& 3& 0& 0\end{array}\right]$ We find the determinant as follows, where as we did previously, we define ${A}_{ij}$ to be the (n-1) x (n-1) matrix you get when you ignore the ith and jth column of the nxn matrix A. $\text{det}\left(A\right)=-2|{A}_{41}|+3|{A}_{42}|$ See how the 4th row was used as it contains 2 zeros, meaning that we only have to actually do any work for two of the terms. Note also how we got the signes for the various components using $\text{sign}\left(i,j\right)=-{1}^{\left(i+j\right)}$. Another way to visualise this is shown below: $\left[\begin{array}{cccc}+& -& +& -\\ -& +& -& +\\ +& -& +& -\\ -& +& -& +\end{array}\right]$ This now needs to be applied recusively, so we figure out the determinants of ${A}_{41}$ and ${A}_{42}$ in the same way.

Let $B={A}_{41}$: $|B|=|\begin{array}{ccc}2& 3& 4\\ 0& 2& 0\\ 1& 2& 3\end{array}|=2|{B}_{22}|=2|\begin{array}{cc}2& 4\\ 1& 3\end{array}|=2\left(2\ast 3-4\ast 1\right)=4$ Note again how we picked row 2 because it only had 1 term which was non-zero and hence made our life easier.

Let $C={A}_{42}$ $\begin{array}{rl}|C|& =|\begin{array}{ccc}1& 3& 4\\ 1& 2& 0\\ 0& 2& 3\end{array}|\\ & =-1|{C}_{21}|+2|{C}_{22}|=-1|\begin{array}{cc}3& 4\\ 2& 3\end{array}|+2|\begin{array}{cc}1& 4\\ 0& 3\end{array}|\\ & =-1\left(9-8\right)+2\left(3-0\right)\\ & =5\end{array}$ We picked row 2 again, but we could have just as easily used columns 1 or 3 to the same effect.

Now we can write: $\begin{array}{rl}\text{det}\left(A\right)& =-2|{A}_{41}|+3|{A}_{42}|\\ & =-2|B|+3|C|\\ & =-2\left(4\right)+3\left(5\right)\\ & =7\end{array}$ We can see this answer verified in the section "Do It In Python"

#### Do It In Python

>>>import numpy as np
>>> A = np.mat("1 2 3 4;1 0 2 0; 0 1 2 3; 2 3 0 0")
>>> np.linalg.det(A)
7.000000000000004

#### See It In HTML

The following is an online matrix determinant calculator app, written in Javascript, to explain calculation of determinant. Define a matrix in the text box using a Matlab-like sytax. For example, "1 2 3; 3 4 5; 5 6 7"