THE WORLD'S LARGEST WEB DEVELOPER SITE

Artificial Intelligence

Matrices

A matrix is set of Numbers.

A matrix is an Rectangular Array.

A matrix is arranged in Rows and Columns.

Matrix Dimensions

This Matrix has 1 row and 3 columns:

C =  
2 5 3

The Dimension of the matrix is (1x3).


This matrix has 2 rows and 3 columns:

C =  
2 5 3
4 7 1

The dimension of the matrix is (2x3).


Square Matrices

A Square matrix has the same number of rows and columns:

C =  
1 2
3 4

C =  
1 -2 3 4
5 6 -7 8
4 3 2 -1

Diagonal Matrices

A Diagonal Matrix has values on the diagonal entries, and zero on the rest:

C =   
2 0 0
0 5 0
0 0 3

Scalar Matrices

A Scalar Matrix has equal diagonal entries and zero on the rest:

C =   
3 0 0 0
0 3 0 0
0 0 3 0
0 0 0 3

The Identity Matrix

The Identity Matrix has 1 on the diagonal and 0 on the rest.

This is the matrix equivalent of 1. The symbol is I.

I =   
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

If you multiply any matrix with the identity matrix, the result equals the original.


The Zero Matrix

The Zero Matrix (Null Matrix) has only zeros.

C =   
0 0 0
0 0 0

Equal Matrices

Matrices are Equal if each element correspond:

2 5 3
4 7 1
  =  
2 5 3
4 7 1

Negative Matrices

The Negative of a matrix is easy to understand:

  -  
-2 5 3
-4 7 1
  =  
2 -5 -3
4 -7 -1

Adding Matrices

If two matrices have the same dimension, we can add them:

2 5 3
4 7 1
 + 
4 7 1
2 5 3
 = 
6 12 4
6 12 4

Subtracting Matrices

If two matrices have the same dimension, we can subtract them:

2 5 3
4 7 1
 - 
4 7 1
2 5 3
 = 
-2 -2 2
-2 2 -2

To add or subtract matrices they must have the same dimension.


Scalar Multiplication

While numbers in rows and columns are called Matrices, single numbers are called Scalars.

It is easy to multiply a matrix with a scalar. Just multiply each number in the matrix with the scalar:

2 5 3
4 7 1
   x 2 =   
4 10 6
8 14 2

Multiplying Matrices

Multiplying matrices is more difficult.

But, if you know how to multiply matrices, you can solve many equations.

Example

You sell roses.

  • Red roses are $3 each
  • White roses are $4 each
  • Yellow roses are $2 each
  • Monday you sold 260 roses
  • Tuesday you sold 200 roses
  • Wednesday you sold 120 roses

What was the value of all the sales?

Red Rose$3 White$4 Yellow$2
Mon1208060
Tue907040
Wed604020
A B C C
$3
$4
$2
 x 
120 80 60
90 70 40
60 40 20
 = 
$800
$630
$380
 = 
$1810

Explanation:

We can only multiply two matrices if the number of rows in matrix A is the same as the number of columns in matrix B.

Then, we need to compile a "dot product":

We need to multiply the numbers in each row of A with the numbers in each column of B, and then add the products:

A B C C
$3
$4
$2
 x 
120 80 60
90 70 40
60 40 20
 = 
$3x120 + $4x80 + $2x60
$3x90 + $4x70 + $2x40
$3x60 + $4x40 + $2x20
 = 
$800
$630
$380

To Transpose a Matrix

To transpose a matrix, means to replace rows with columns.

A =   
1 2
3 4
    AT =  
1 3
2 4