# 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".

## Page Contents

## Vector Stuff

### Vector Spaces

References:

- What isn't a vector space?, Mathematics Stack Exchange.
- Things that are/aren't vector spaces, Dept. of Mathematics and Statistics,University of New Mexico.
- Vector Spaces, physics.miami.edu.
- Vector space, Wikipedia.

A vector is an element of a *vector space*. A *vector space*, also known as a
*linear space*, , is a set which has addition and scalar multiplication defined
for it and satisfies the following for any vectors , , and and scalars
and :

1 | Closed under addition: | |

2 | Communative: | |

3 | Associative: | |

4 | Additive identity: | |

5 | Inverse: | |

6 | Closed under scalar multiply: | |

7 | Distributive: | |

8 | Distributive: | |

9 | Distributive: | |

10 | Multiply identity: |

#### Functions Spaces

First let's properly define a function. If and are sets and we have and ,
we can form a set that consists of *ordered* pairs . If it is the case that
, then is a function and
we write . This is called being "single valued", i.e., each input to the
function is unambiguous. Note, is not a function, it is the value *returned* by
the function: is the function that defines the mapping from elements in (the *domain*)
to the elements in (the *range*).

One example of a vector space is the set of real-valued functions of a real variable, defined on the domain . I.e., we're talking about where each is a function. In other words, 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, . 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, and the following are linear combinations: 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 is called the *span* of those vectors:
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 and . 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 added to all the possible scalings of . One can use this to imagine that if we added all the possible scalings of to all the possible scalings of we would reach every coordinate in . Thus, we can say that the set of vectors spans , or .

From this we may be tempted to say that any set of two, 2d, vectors spans but we
would be wrong. Take for example and . 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 .

Lets write the above out a little more thoroughly... The span of these vectors is, by our above definition: Which we can re-write as: ... which we can clearly see is just the set of all scaled vectors of . Plainly, any co-linear set of 2d vectors will not span .

### Linear Independence

We saw above that the set of vectors are co-linear and thus did
not span . 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 spans , but is redundant because we can remove it from the set of vectors and still have a set that spans . 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:
Thus a set of vectors is linearly **independent** when the following is met:
Sure, this is a definition, but why does this mean that the set is linearly *dependent*?

Think of vectors in a . 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 , no matter how small we make that scaling, we cannot find a scaling of that when added to will get us back to the origin. Thus we cannot find a linear combination where and/or 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 .

### Linear Subspace

If is a set of vectors in , then is a *subspace* of
if and only if:

**contains the zero vector**:**is closed under scalar multiplication**:**is closed under addition**:

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 because the set obeys all of the above rules.

A very useful thing is that a *span is always a valid subspace*. Take, for example,
. 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.
Second, is it closed under scalar multiplication? Because the span is the set of *all*
linear combinations, for any set of scalars ...
... 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 , which is just a line, is a subspace of .

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, is a subspace of (where each vector ). We also know that a span is the set of all possible linear combinations of these vectors.

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

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

Put more formally: Let be a subspace of . A subset is a basis for iff the following are true:

- The vectors span , and
- They are linearly
*in*dependent.

A subspace can have an infinite number of basis, but there are *standard basis*. For
example in the standard basis is . 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 , where is the subspace.

Thus, we can say that every subspace of has a basis and .

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:

- Form a matrix where the j
^{th}column vector is the j^{th}vector . - Reduce the matrix to row-echelon form.
- Tak the column vectors that contain a pivot and these are the basis vectors.

TODO discuss the canonical vectors in R2 and R3. , ... but we could also have , .

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:

### 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: Written more succinctly we have: 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: | |

Distributive: | |

Associative | |

Cauchy-Schwartz Inequality | , where is non-zero. |

Vector Triangle Inequality |

#### Angle Between Vectors

The dot product also defines *the angle between vectors*. Take two unit vectors and .
We can calculate:
We know that:
And we know that:
Therefore, by substitution:
Thus, ** describes the angle between unit vectors**. If the vectors are not unit
vectors then the angle is defined, in general, by:

#### Vector Length

### Vector Transposes And The Dot Product

In linear algebra vectors are implicitly column vectors. I.e., when we talk about we mean: Thus, the transpose of is a row vector: We can then do vector multiplication of the two like so: So, in general .

### Dot Product With Matrix Vector Product

If is an mxn matrix and then .

Then, if then is also well defined and:
Thus we can say **.
**

### Unit Length Vectors

A unit vector is a vector that has a length of 1. If is a vector (notice the special symbol used) then we defined its length as: Thus if a vector is a unit vector then .

Interesting we can also write .

To construct a unit vector where , we need the sum to also be 1! How do we achieve this if ? 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: is at 90 degrees to both and .
is at 90 degrees to and , and is at
90 degrees to and .

In any set of any vectors, , 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 and 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.

We know when two **vectors are orthogonal when their dot product is
zero: 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

The vector is the vector rotated by degrees.
We can use the following
trig identities:
Substitute these into the formulas above, we get the following.
Which means that...
For a 90 degree rotation we know that
and . Substiuting these values into the above equations
we can clearly see that...
Therefore, any vector in 2D space that is will become
and therefore the dot product becomes . 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: :

Here and represent the magnitude of the vectors , , and , . represents the magnitude of the vector . Thus, we have this:

I.e., .

When the angle between the vectors is 90 degrees, and so that part of the equation disappears to give us . Now... Recall that and that therefore .

Based, on this we can say that... Now, all of the and terms above will be cancelled out by the and terms, leaving us with... 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

- Associative:
- Distributive: and
- Identity:
- Zero:
- Closure: is a matrix of the same dimensions as .

Note that scalar multiplication is *not* commutative: !

#### Matrix Addition

- Commutative:
- Associative:
- Zero: For any matrix , there is a unique matrix such that
- Inverse:
- Closure: , is a matrix of the same dimensions as and .

#### Matrix Multiplication

- Associative:
- Distributive:
- Identity:
- Zero:
- Inverse: Only if is a
*square*matrix, then is its inverse and . Note that*not all matrices are invertible*. - Dimension: If is an matrix and is an matrix then is an matrix.

Note that matrix multiplication is *not* commutative: !

Be careful: the equation does not necessarily mean that or and for a general matrix , , unless is invertible.

#### Matrix Transpose

- Associative:
- Distributive (into addition):
- Distributive (into mult):

Generalises to - Identity:
- Inverse:
- Name?:
- Name?:
- Name?:
- If columns of are LI then columns of are LI. is square and also invertible.

#### Matrix Inverse

- Associative (self with inverse):
- Distributive (into scalar mult):
- Distributive (into mult):
- Identity:
- Name?:
- Name?:

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

References:

- Lecture 18: The Rank of a Matrix and Consistency of Linear Systems, Ohio University.
- Types of Solution Sets.
- Row Echelon Form and Number of Solutions.

The set of linear equations:
Can be represented in matrix form:
Any vector , where , 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**:
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:
But, this next one is not:
We go from a matrix to the equivalent in row-echelon form using **elementary row operations**:

- Row interchange:
- Row scaling:
- Row addition:

In row echelon form:

- All rows containing only zeros appear below rows with nonzero entries, and
- 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:

- If a row has all zeros then it is below all rows with a non-zero entry.
- The left most entry in each row is 1 - it is called the
*pivot*. - The left most non-zero entry in each row is the only non-zero in that column.
- 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:

- All pivots are equal to 1, and
- 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 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 :

*No Solution*. If the last (augmented) column of (ie. the column which contains ) contains a pivot entry.*Restructed Solution Set*. If the last row of the matrix is all zeros except the pivot column which is a function of .*Exactly One Solution*. If the last (augmented) column of (ie. the column which contains ) does not contain a pivot entry and all of the columns of the coefficient part (ie. the columns of ) do contain a pivot entry.*Infinitely Many Solutions*. If the last (augmented) column of (ie. the column which contains ) does not contain a pivot entry and at least one of the columns of the coefficient part (ie. the columns of ) also does not contain a pivot entry.

Let's look at a quick example of a matrix in echelon-form:

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: From (1) we know: Substitute (4) back into (2): Substitute (5) and (4) back into (1):

We can use RREF to accomplish the same thing and find the solutions to the above. 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**, , which in this case is:
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: Now we have two free variables! Now and where and can be any values we like. Now the general solution vector looks like this: How did we get here? We we know from the RREF matrix that: We replace and 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**:
The **solution set** thus becomes:

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: We'd make an augmented matrix like so: 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:

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:

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, , and vector we can say that,

### Null Space Of A Matrix

#### Definition

For an nxm vector , the nullspace of the nxm matrix , is defined as follows:
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 (). The solution space set to this is the null space.

The system of linear equations is called **homogeneous**. It is always
**consistent**, i.e., has a solution, because is always a solution (and is called the **trivial** solution).

*The null space of a matrix is a valid subspace of * because
it satisfies the following conditions, as we saw in the
section on subspaces.

**contains the zero vector**:**is closed under scalar multiplication**:**is closed under addition**:

It can also be shown that , where 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:
Recalling how we can write out vector/scalar multipication,
we get,
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 **.

#### 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 , 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 , i.e... We find the solution set using the normal augmented matrix method: There are no free variables, so therefore the solution set can contain only the zero vector because we have three contraints and . The only values for the '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: We find the solution set using the normal augmented matrix method: Now we can see that and . The variable , however, is free. It can take any value. Let's call that value . The solution vector is therefore: The general solution vectors is therefore: So we can say the null space is:

##### 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 : We thus know that: And that and are free variables. This means that the general solution is: And therefore we can define the null space as:

#### 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 , then the

null-space is ... the set of all vectors that are sent to the zero vectorby . Think of this as theset of vectors thatlose their identityas 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*, . 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 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 *.
The column space of A is a valid subspace.

For the system of equations , is the set of all values that can be. We can look at this this way: The solution, , can be seen to be a linear combination of the column vectors of . Thus, .

Therefore, if and , 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 are LI if and only if . So we can figure out if we have a basis by looking at 's null space. Recall that and that the column vectors of a matrix A are LI if and only if !

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 * :) 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 , pick the columns from that correspond to (have the same position as) the pivot columns in .

A really interested property of the column space is the **column space criterion** which states that a linear system, has a solution iff 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 . You can get this by counting the pivot columns in .

The **rank equation** is , where is an matrix.

If is reduced to row-echelon form , then:

- is the number of free variables in solution space of , which equals the number of pivot-free columns in .
- is the number of pivots in .
- , equals the number of columns of .

TODO: https://math.stackexchange.com/questions/21100/importance-of-matrix-rank

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

Really good answer by John-Paul Meyer on the Khan Academy website:

... 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:

- be linearly independent and
- span the space.
The "space" could be, for example: , , , ... , 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 **.
If we take a general matrix and multiply it by it's transpose we get...

The pattern looks pretty familiar right?! It looks a lot like
, our formula for the dot product of two vectors. So,
when we say , , and , we will get the following:
a matrix of two *row vectors* , .
If our vectors and are orthogonal,
then the component 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 and ... 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 ? It doesn't if we use our original matrix A!... Oops, we can see that we didn't get the identity matrix!! But, perhaps we can see why. If was a matrix of row vectors then is a matrix of column vectors. So for 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 it would follow that for this to work now was to be a matrix of column vectors because we get back to our original ( would become a mtrix of row vectors):

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 is defined as follows... Then we write the determinate of B as...

A **matrix is invertible iff **. We can define the inverse as follows using the determinant:
It is defined as long as .

If is a 3x3 matrix defined as follows, where the elements represents the element at row and column : We can define the determinant as: Same rule applies: If the determinant is not zero then the matrix will be invertible.

We've used the first row () 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 multiplied by the determinant of the 2x2 matrix you get if you take out the i^{th} row and j^{th} column of
the matrix.

This generalises to an nxn matrix as follows:
Define to be the (n-1) x (n-1) matrix you get when you ignore the i^{th} and j^{th} column of the nxn matrix A.

Then we can define the determinant *recursively* as follows:
For each , 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:

A quick example. is defined as follows:
We find the determinant as follows, where as we did previously, we define to be the (n-1) x (n-1) matrix you get when you ignore the i^{th} and j^{th} column of the nxn matrix A.
See how the 4^{th} 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 . Another way to visualise this is shown below:
This now needs to be applied recusively, so we figure out the determinants of and in the same way.

Let : Note again how we picked row 2 because it only had 1 term which was non-zero and hence made our life easier.

Let 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: 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`

", defines the 3x3 matrix:
Use it to create matricies to see, step by step, with explanations, how the determinant is calculated. Just replace the text in the message box below and hit the button to see how you can solve for the determinant of your matrix...

#### Rule Of Sarrus

For a 3x3 matrix defined as follows: The determinant is defined as: Notice how it is the diagonals (wrapped) summed going from left to right, and the diagonals (wrapped) subtracted going from right to left.

#### Effect When Row Multiplied By Scalar

Multiplying a row in a matrix by a scalar multiplies the determinant by that scalar. This is shown anecodtally below.

#### Effect When Matrix Multiplied By Scalar

Multiplying an entire nxn matrix by a scalar, scales the determinant by n^{2}. Shown anecdotally below:

#### Row Op: Effect Of Adding A Multiple Of One Row To Another

Say that A is defined as follows:
Now lets say we apply the row operation Row_{1} = R_{1} + kR_{2} to get the matrix:
Now...
I.e. adding a multiple of one row to another doesn *not* change the determinant, as shown
anecdotally above! Works that same if we do Row_{1} = R_{1} **-** kR_{2}.

#### Row Op: Effect Of Swapping Rows

Swapping A's rows and taking the determinant gives us: So, we can see that for a 2x2 matrix, swapping rows changes the sign of the determinant. Generalise to nxn.

#### Effect Of Adding A Row From One Matrix To Another

Let's say we have two matricies: Create a new matrix by adding the second column of A to B: We will find out that the derminant of Z is the sum of the determinants for A and B: Generalises to nxn matricies.

#### When A Matrix Has Duplicate Rows

We have seen that when we swap two rows that the determinant is negated. But, if we swap two identical rows the matrix determinant should not change! The only way this can be true is if the determinant is zero.

This, somewhat anecodtally, we can say that **if a matrix has a duplicate row then it's determinant
must be zero!** The same is true if one row is a simple scalar multiple of another.

We have also seen that the inverse of a matrix is only available when its determinant is
non-zero. Therefore we now know that **matricies with duplicate rows are not invertible**.
Same still applies if on row is a scalar multiple of another.

#### Upper Triangular Determinant

An **upper triangular matrix** is one where everything below the diagonal is zero. For upper
triangular matricies the determinant is the multiplication of the diagonal terms:
And:
This generalises to nxn matricies:
The same applies to lower triangular matrixies.

This method gives us a way of getting more efficient determinants for matricies if we can get them into an upper or lower diagonalisation. The Khan lectures give this example of a matrix reduction (remember that we saw that adding multiples of one row to another does not change the determinant): Note the minus because a row was swapped to do the reduction!

#### The Determinant And The Area Of A Parallelogram

This is one of the better YouTube tutorials I've found that explains the *concepts* and not just the
mechanics behind determinants, by 3BlueBrown (awesome!).

Now, onto more notes from Khan Academy, which also give an abolsolutely awesome explanation! Also, this Mathematics StackExchange Post gives loads of different ways of proving this.

For two vectors, each made a column vector of a matrix A, the **determinant of A gives the area of the parallelogram formed by the two vectors**:

Put a little more mathsy-like, if you have two vectors, call them, and , then the area of the parallelogram formed by the vectors, as shown above, is given by:

To aid in the following explanation you might need to refer to the section on projections.

The area of a parallelogram is given by the base times the height. In the above we can see that the base of the parallelogram is just the length . The height of the parallelogram, we can see is . So... Get rid of the square roots by squaring both sizes: Now we have to solve the dot products, which means we will have to define our two vectors like so: Substituting these vector definitions into the above we can expand out the dot products:

Now, in the section on linear transforms, we will see that the columns vectors of the transform matrix show what happens to the canocial basis vectors. Thus, if the determinant of the transformation matrix is the area of the parallelogram formed by the column vectors of the matrix, the **determinant gives us the scaling factor of the transformation!**

### Rowspace & Left Nullspace & Orthogonal Complements

#### Left Null Space Definition

Notes based on Khan Academy with extra reference to MIT Linear Algebra eBook Chapter.

We saw in the 3rd null space example the following matrix, and its reduction to RREF:
We calculate the null space by setting up an augmented matrix to solve for :
Giving...
But, we also know that because only the first column in the RREF form has a pivot entry, the basis for the column space of the matrix only contains the first column vector:
We also know the rank of the matrix:
Now we take the transpose of :
So, now we can calculate the nullspace of the transpose of A. We see that and that is a free variable so:
The ** is called the left null space of **. Why have we called in the left null space?
Have a look at this...
...by the very definition of what a null space is. We are solving for :
Thus, the null space of can also be defined as so:
Now we see why it is called the "left" null space: the vector is on the LHS of the transformation matrix!

#### Rowspace

The rowspace of the transformation is defined as : Recall from above: The only pivot column is the first, so:

#### Relationship Between The Spaces: Orthogonal Complements

An orthogonal complement is defined as follows. If is a subspace of , the orthogonal complement of is written as is defined as so: In other words, every member of is orthogonal to every member of .

It can be shown that is a valid subspace: it is closed under addition and scalar multiplication.

To find the orthogonal complement of , take its generating vectors and place them as row vectors in a matrix. If, and the generating set of vectors, or span, of is then form the by matrix: In the above matrix, becomes the row space of . Because the null space of is the orthogonal complement of this matrix, the orthogonal compement to your subspace is found by finding the null space of the above matrix!

The **null space and row space are perpendicular**. They are orthogonal complements. Thus we can say:

^{th}row vector of .

We know that, by the definition of matrix definition we can say the following: The above is just the the matrix multiplication shown above written out. But, we know that is the same as the dot product, so it is equal to . I.e., the row vectors of must all be orthogonal to if is a member of the null space.

Thus, the vectors in the null space are to the column vectors of . Thus, .

If we let , then and thus .

#### Relating The Dimension Of A Subspace To Its Orthogonal Complement

The **dimensions of each subspace can also be related**: , where is a subspace of . This, therefore, means that if , then .

#### Representing A Vector As A Combination Of A Vector In A Subspace And One In Its Orthogonal Complement

This relation implies that . So, if is a basis for then is a basis for . This
leads us to an importan property where we can say that **any vector in can be represented uniquely by some vector in a subspace of and some vector in **:

We can also notice something important about the **intersection of a subset and its orthogonal complement**: if and then . I.e. .

#### Unique Rowspace Solution To

We have seen that any vector in can be represented as a combination of and .

So if is a solution to , where , then we can express as where and .

I.e., the solution is a linear combination of some vector in the rowspace of and some vector in the null space of .

Thus, , which means that is a solution!

We have also seen, in the section on the column space that the solution, if it exists, must be in the column space of . Therefore, for any vector, , in the column space of , there is a *unique* vector, in the rowspace of that is the solution. Woah!!

It can also be shown that this is a unique solution. Proof ommited.

To summarise: any solution to can we written as and we know there is a unique solution in the rowspace of A, .

This means that we can also write:

This is a very important point, as we'll see later on when this gets applied to things like least square
estimation. **If , then such that is a solution to and no other solution has a length less than **.

#### Summary

The orthogonal complement of a subspace has the following properties:

- is a subspace of .
- .
- .
- Each vector in can be expressed unqiuely in the form for and .
- If , then such that is a solution to and no other solution has a length less than

#### A Visual Exploration

We know that the nullspace of is defined as and that , so we can determine the null space by reducing to its RREF as so: Now the rowspace, aka : We have seen that the column space of a matrix will be the column vectors associated with the pivot columns. Therefore:

So, what about the solution set? We can see that the solution set is a scaled vector from the null space plus some particular solution. These can be plotted as so:

We can also see that, as we discovered previously, the shortest solution to the problem is the vector formed by the null-space vector scaled to zero plus a vector in the rowspace:

### Eigenvectors and Eigenvalues

Stackoverflow thread: What is the importance of eigenvalues and eigenvectors.

Eigenvectors and values exist in pairs: every eigenvector has a corresponding eigenvalue. An eigenvector is a direction, ... An eigenvalue is a number, telling you how much variance there is in the data in that direction ...

## Linear Transformations

### Functions

#### Scalar Functions

Normally a function is a *mapping* between two sets: from a *domain* to a *range*, which is
a subset of the function's *co-domain*. I.e., the co-domain is the set of all possible things the
function could map onto and the range is the subset of the co-domain containing the things the
function actually maps to. If we have two sets, and , we say that if is a function, then it associates elements of