Skip to content

Maths 101: Matrix Multiplication

May 25, 2013

Charles

I’ve started so i’ll finish – we’re going to dig into matrix multiplication; once I’ve covered this we’ll dive into determinants and back to matrix inversion. Theres a reason for this which we’ll understand along the way – i’ll throw in the identity matrix and mean which are great for validation and dimensional understanding. Onto matrix multiplication then:

With matrix multiplication, we’re actually on face value doing sort of addition but internally multiplication – your’ll see this more when working with the inverse. Crucially there are two things that matter in matrix multiplication: firstly the multiplication rule, which is dependent of the second thing – A matrix can ONLY be multiplied by another matrix if it has the same amount of columns as the other has rows. Given two matrices:

A B C
D E F

X I
Y K
Z J

We start by taking the first value of the first row of first matrix! (A) and multipling it by the same element of the second matrix, like so (A * X). Now instead of following this pattern E.g. (B * I), we move down the column of the second matrix, so (B * Y). We can see now why the second matrix needs the same amount of rows as the first has columns. Colour coding this with the first row of the first matrix and with the first column of the second we can see the rule in action:

A B C
D E F

X I
Y K
Z J

We take the sum of these multiplications and treat it as the first value of the first row of the new matrix:

(AX) + (BY) + ( CZ)

The entire matrix looking like so:

(AX) + (BY) + (CZ) , (AI) + (BK) + (CJ)

(DX) + (EY) + (FZ) , (DI) + (EK) + (FJ)

Crucially we move along the first matrices rows as we do with the second matrices columns. Pseudo code could look something like this (might be off):

For i in matrix B’s column length:

For j in matrix B’s row length:

Sum (Multiply A[i][j] by B[j][i])

Now if you wanted to multiply a matrix by itself that wasn’t square i.e. it didn’t have the same amount of columns as rows; this would be where you’d create a transposed version of the matrix and multiply it by that E.g. To multiply:

A B C
D E F

by itself, you’d create a new matrix transposing the original like so:

A D
B E
C F

And multiply these two using the rule stated above:

(AA) + (BB) + (CC) , (AD) + (BC) + (CF)

(DA) + (EB) + (FC) , (DD) + (EE) + (FF)

Next we’ll break into determinants; which we’ll try to formulate recursive a function for any n x m square matrix.

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: