Tuesday, March 5, 2013

Matrices


Definition of Matrix

A matrix is a collection of numbers arranged into a fixed number of rows and columns. Usually the numbers are real numbers. In general, matrices can contain complex numbers but we won't see those
here. Here is an example of a matrix:
The upper left corner of the matrix is row 1 column 1. In the above matrix the element at row 1 col 1 is the value a1,1. The element at row 2 column 3 is the value a2,3.

Names for Matrices

If you sometimes forget whether rows or columns come first, just remember that matrices are build out of rowman columns. A matrix can be given a name. In printed text, the name for a matrix is usually a capital letter in bold face, like A or M. Sometimes as a reminder the dimensions are written to the right of the letter, as in B3x3.
The elements of a matrix also have names, usually a lowercase letter the same as the matrix name, with the position of the element written as a subscript. So, for example, the 3x3 matrix A might be written as:

Sometimes you write A = [aij] to say that the elements of matrix A are named aij.

 



Square Matrix :
     Any matrix that has equal number of rows and columns is called square matrix. E.g: 2x2, 3x3 matrix.


2x2 Square Matrix3x3 Square Matrix
a11a12
a21a22
2 rows & 2 columns
b11b12b13
b21b22b23
b31b32b33
3 rows & 3 columns



Diagonal Matrix :
     A Diagonal matrix is a square matrix with numbers on the leading diagonal and zeros in all other places.

Diagonal Matrix
200
030
008


Identity Matrix :
     An identity matrix is a square matrix denoted as I. It has ones (1) down the leading diagonal and zeros in all other places.

2x2 identity3x3 identity
10
01
100
010
001

Note: Any matrix multiplied by its identity matrix leaves the matrix unchanged.
It is similar to multiplying a number by 1.
i.e AI = A (where A is a matrix)

22
53
x
10
01
=
22
53
Zero (Null) Matrix :
      A zero or null matrix is a matrix with 0 as the element for all its cells (rows and columns).

Zero (null) Matrix
000
000
000


Symmetric Matrix :
      A symmetric matrix is a matrix where aij = aji. i.e an element at the ith row, jth columns should be equal to the element at the jth row, ith columns.

Symmetric Matrix
123
245
356


Equality Matrix :
     For any two matrices to be said as equal matrices they should be of same size and have same values.

Matrix Equality

For two matrices to be equal, they must have
  1. The same dimensions.
  2. Corresponding elements must be equal.
In other words, say that An x m = [aij] and that Bp x q = [bij].
Then A = B if and only if n=p, m=q, and aij=bij for all i and j in range.
Here are two matrices which are not equal even though they have the same elements.
 
 
   
Matrix Addition
If two matrices have the same number of rows and same number of columns, then the matrix sum can be computed:
If A is an MxN matrix, and B is also an MxN matrix, then their sum is an MxN matrix formed by adding corresponding elements of A and B
Here is an example of this:
 
 

Addition and Subtraction example

  Multiplication of a Matrix by a Scalar

A matrix can be multiplied by a scalar (by a real number) as follows:
To multiply a matrix by a scalar, multiply each element of the matrix by the scalar.
Here is an example of this. (In this example, the variable a is a scalar.)



Multiplying a Matrix by Another Matrix

But to multiply a matrix by another matrix you need to do the "dot product" of rows and columns ... what does that mean? Let me show you with an example:
To work out the answer for the 1st row and 1st column:
Matrix Multiply
The "Dot Product" is where you multiply matching members, then sum up:
(1, 2, 3) • (7, 9, 11) = 1×7 + 2×9 + 3×11 = 58
We match the 1st members (1 and 7), multiply them, likewise for the 2nd members (2 and 9) and the 3rd members (3 and 11), and finally sum them up.
Want to see another example? Here it is for the 1st row and 2nd column:
Matrix Multiply
(1, 2, 3) • (8, 10, 12) = 1×8 + 2×10 + 3×12 = 64
We can do the same thing for the 2nd row and 1st column:
(4, 5, 6) • (7, 9, 11) = 4×7 + 5×9 + 6×11 = 139
And for the 2nd row and 2nd column:
(4, 5, 6) • (8, 10, 12) = 4×8 + 5×10 + 6×12 = 154
And we get:
Matrix Multiply

Matrix Subtraction

If A and B have the same number of rows and columns, then A - B is defined as A + (-B). Usually you think of this as:
To form A - B, from each element of A subtract the corresponding element of B.
Here is a partly finished example:
 
 

Transpose

The transpose of a matrix is a new matrix whose rows are the columns of the original (which makes its columns the rows of the original). Here is a matrix and its transpose:




The superscript "T" means "transpose". Another way to look at the transpose is that the element at row r column c in the original is placed at row c column r of the transpose. The element arc of the original matrix becomes element acr in the transposed matrix.
Usually we will work with square matrices, and it is usually square matrices that will be transposed. However, non-square matrices can be transposed, as well:

Rule for Transpose

If a transposed matrix is itself transposed, you get the original back:

This illustrates the rule (AT)T = A.

Determinant

The determinant of a matrix is a special number that can be calculated from the matrix. It tells us things about the matrix that are useful in system linear equations, in calculus and more.
The symbol for determinant is two vertical lines either side.
Example:
|A| means the determinant of the matrix A

Calculating the Determinant

First of all the matrix must be square (i.e. have the same number of rows as columns). Then it is just a matter of basic arithmetic. Here is how:

For  2×2 Matrix

For a 2×2 matrix (2 rows and 2 columns):
A Matrix
The determinant is:
|A| = ad - bc
"The determinant of A equals a times d minus b times c"
It is easy to remember when you think of a cross:
  • Blue means positive (+ad),
  • Red means negative (-bc)
A Matrix

Example:

A Matrix
|B| = 4×8 - 6×3
= 32-18
= 14

For  3×3 Matrix

For a 3×3 matrix (3 rows and 3 columns):
A Matrix
The determinant is:
|A| = a(ei - fh) - b(di - fg) + c(dh - eg)
"The determinant of A equals ... etc"
It may look complicated, but there is a pattern:
A Matrix
To work out the determinant of a 3×3 matrix:
  • Multiply a by the determinant of the 2×2 matrix that is not in a's row or column.
  • Likewise for b, and for c
  • Add them up, but remember that b has a negative sign!
As a formula (remember the vertical bars || mean "determinant of"):

"The determinant of A equals a times the determinant of ... etc"

Example:

A Matrix
|C| = 6×(-2×7 - 5×8) - 1×(4×7 - 5×2) + 1×(4×8 - -2×2)
= 6×(-54) - 1×(18) + 1×(36)
= -306

Inverse of a Matrix
using Minors, Cofactors and Adjoint

You can calculate the Inverse of a Matrix by 1) calculating the Matrix of Minors, 2) then turn that into the Matrix of Cofactors, 3) then the Adjoint, and 4) multiply that by 1/Determinant.
But it is best explained by working through an example!

Example: find the Inverse of A:

It needs 4 steps. It is all simple arithmetic but there is a lot of it, so try not to make a mistake!

Step 1: Matrix of Minors

The first step is to create a "Matrix of Minors":
For each element of the matrix:
Put those determinants into a matrix (the "Matrix of Minors")

Determinants

For a 2×2 matrix (2 rows and 2 columns) the determinant is easy: ad-bc
Think of a cross:
  • Blue means positive (+ad),
  • Red means negative (-bc)
A Matrix

The Calculations

Here are the first two, and last two, calculations of the "Matrix of Minors" (notice how I ignore the values in the current row and columns, and calculate the determinant using the remaining values):
And here is the calculation for the whole matrix:

Step 2: Matrix of Cofactors

This is easy! Just apply a "checkerboard" of minuses to the "Matrix of Minors". In other words, you need to change the sign of alternate cells, like this:

Step 3: Adjoint (also called Adjugate)

Now "Transpose" all elements of the previous matrix... in other words swap their positions over the diagonal (the diagonal stays the same):

Step 4: Multiply by 1/Determinant

Now find the determinant of the original matrix. This isn't too hard, because we already calculated the determinants of the smaller parts when we did "Matrix of Minors".
A Matrix
So: multiply the top row elements by their matching "minor" determinants:
Determinant = 3×2 - 0×2 + 2×2 = 10


And now multiply the Adjugate by 1/Determinant:










 


Inverse of a Matrix
using Elementary Row Operations

Also called the Gauss-Jordan method.
This is a fun way to find the Inverse of a Matrix ...
... play around with the rows
(adding, multiplying and swapping them)
until you make your Matrix A
into the Identity Matrix I.
And by ALSO doing the changes to an
Identity Matrix it magically turns
into the Inverse!

The "Elementary Row Operations" are simple things like adding rows, multiplying and swapping ... but let me show you with an example!

Example: find the Inverse of "A":

We start with the matrix A, and write it down with an Identity Matrix I next to it:

(This is called the "Augmented Matrix")

Identity Matrix

The "Identity Matrix" is the matrix equivalent of the number "1":
Identity Matrix
A 3x3 Identity Matrix
  • It is "square" (has same number of rows as columns),
  • It has 1s on the diagonal and 0s everywhere else.
  • It's symbol is the capital letter I.

Now we do our best to turn "A" (the Matrix on the left) into an Identity Matrix. The goal is to make Matrix A have 1s on the diagonal and 0s elsewhere (an Identity Matrix) ... and the right hand side comes along for the ride, with every operation being done on it as well.
But we can only do these "Elementary Row Operations":
  • swap rows
  • multiply or divide each element in a a row by a constant
  • replace a row by adding or subtracting a multiple of another row to it
And we must do it to the whole row, like this:

Start with A next to I

In this example my first step was to add row 2 to row 1,

then divide row 1 by 5,

Then take 2 times the first row,
and subtract it from the second row,

Multiply second row by -1/2,

Now swap the second and third row,


Last, subtract the third row from the second row,

And we are done!
And matrix A has been made into an Identity Matrix ...
... and at the same time an Identity Matrix got made into A-1


No comments: