Matrices - Basic operations
Matrices are one of the most used Math abstraction nowadays, specially in the field of machine learning. That’s why I encounter myself lately reviewing matrices theory. Now with the most basic operations: sum and multiplication.
SUM
Before adding up two matrices they must have the same dimensions, the same number of lines and columns. Once we’ve got two valid matrices, we have to add up each correspondent pair of both matrices, a1,1 + b1,1, a1,2 + b1,2 … an,m + bn,m.
So, lets say we have a matrix A and a matrix B and lets add them up:
Matrix addition has a number of properties worth knowing, such as: commutative, associative, the additive identity and the additive inverse.
COMMUTATIVE
If A and B are matrices of the same order then it doesn’t matter the order in which you add them up, in other words A + B = B + A. Lets prove it, lets make A and B to be two real matrices:
So lets do A + B and then B + A to check that both operations have the same result:
ASSOCIATIVE
Matrix addition is associative. This says that, if A, B and C are Three matrices of the same order then you will get the same result whether you add A to (B + C) or (A + B) to C. Lets prove it by defining three matrices:
Now lets define B + C AND A + B:
Finally:
ADDITIVE IDENTITY
Let A be the matrix then, A + O = A = O + A Therefore, O a matrix of the same order as the matrix A that when added up to A equals to A as well. O is also named the null or zero matrix. So lets prove it adding up a matrix A with a compatible zero matrix. First the two matrices:
Now adding up A to O must result in A:
ADDITIVE INVERSE
Let A be the matrix then, A + (- A) = O = (- A) + A where -A is the inverse of A. The inverse of a matrix is the matrix obtained by changing the sign of every matrix element. Having A and -A:
So basically adding up -A to A will end up giving O (the null matrix):
And the opposite works the same:
MULTIPLY
If A is a matrix of order m x n and B is another matrix with order o x p where m and o are number of rows and n and p are number of columns, in order to be able to multiply A x B, then n == o must be true, meaning that the number of columns of A must be equals the number of rows in B, and the resulting matrix will be of order m x p:
How is the procedure of multiplying two matrices ? Well, the element Ci,j (where i is the row and j is the column) will be the result of multiplying the elements of Ai by the elements Bj and adding up their results. So for example, when multiplying A x B = C:
Here’s an example, there’re two matrices A and B:
Then in order to get c1,1 we need to multiply elements from a1,… and b…,1 and then add them up:
Now in order to get c1,2 we need to multiply elements from a1,… and b…,2:
And this would go on and on for remaining cells:
Finally simplifying:
The matrix multiplication has a few properties: the associative the distributive and the multiplicative identity. Lets view them all with examples. I’m using the following matrices:
Associative
This should be called pseudo-associative due to the fact that the order to the elements in a matrix multiplication matters. AB and BA may not result in the same solution. |
The associative property says that A(BC)=(AB)C. So lets calculate A(BC) first and then (AB)C and compare both results:
Then A(BC):
Distributive
When multiplying three different matrices A, B and C the distributive property says that A(B+C) = AB + AC and also that (A+B)C = AC + BC. So again having the previous A, B and C matrices, lets do a couple of calculations:
A(B+C) = AB + AC
(A+B)C = AC + BC
Multiplicative identity
The multiplicative identity property says that there’s an identity matrix. When a matrix is multiplied by this identity matrix the result is the matrix itself. The mathematical formula would be AI = A = IA where I is the identity matrix.