Matrices
Reviewing Some Basic Operations



Defining Matrices

Let’s start by taking a look at the following two matrices.

Matrices are measures rows X columns. is a matrix and is a matrix.

Elements in a matrix are also defined by their row and column. For instance, corresponds to row and column . Looking above, and .

Vectors

A vector is an matrix.

By convention, vectors are defined as lowercase letters and matrices use uppercase.

Matrix Addition and Subtraction

We can only add matrices or vectors that have the same dimensions.

As you can see we add the values based on their row and column. Row 1 column 1 is combined with row 1 column 1 from the second matrix.

Subtraction works in the same way.

An operation like the following would not work because the dimensions are not the same.

Matrix - Scalar Multiplication

For scalar multiplication we multiply every element by the scalar. Scalar multiplication always returns the same dimensions.

Matrix - Vector Multiplication

For valid matrix multiplication we need the number of columns in the first matrix to equal the number of rows in the second. This is the same for vectors and matrices as a vector is just a matrix with one column.

The following would not be valid because there are more rows in the second matrix than columns in the first matrix.

However, if we remove a row from the second matrix it would work.

What this is saying is for the first column in the resulting matrix, we are grabbing 1 of column 1 and combining it with 2 of column 2.

If we expand our multiplier to our resulting matrix will be .

Paying attention to the second column in the result, we see that we combined 2 of the first column and 4 of the second column.

The multiplier simply tells us how many of each row to grab for a specific column.

Matrix Multiplication Properties

however

Examples

Matrix Multiplication Applied

More info about the hypothesis function

Let’s say we have a hypothesis function . We are going to assume this function is the best fit for determining housing prices given a square footage.

In the following matrix the first column is contains all identities, or ones, and the second column contains house sizes.

This second matrix represents our hypothesis function.

What happens is the in the first column keeps as is because it it the equivalent of multiplying by . The second column is multiplied by .25 and is combined with .

We could also test multiple hypothesis at once by adding more columns to the multiplier like so.

Each resulting column is a different hypothesis.

*****
Written by Justin on 13 November 2015