freeCodeCamp/guide/english/mathematics/intro-to-matrices/index.md

2.1 KiB

title
Intro to Matrices

Intro to Matrices

A matrix is a 2D array of values. Below you can see how its organized.

alt text

It is composed by rows, and columns. Each position can be found with (row number, column number). For example, if you want the number 7 of the matrix below, you need to get the element on the position (2,3), second row (because it is the row number), third column (because it is the column number). Another example would be if you want to get the position of the number 1 below. The position would be (2, 1) because it is on row 2 and column 1.

alt text

The usuals operations works for matrices, but adddition and subtraction is made on the elements of the same position (so the two matrices needs to have the same size). Multiplication is different so matrix A x matrix B, A needs to have the same size of transpose of B.

Transpose is the operations of inver the rows and columns of a matrix.

alt text

You can also think of it as the column num of matrix A needs to be the same as the row size of matrix B. The size of the new array is the row num of matrix A and the column num of matrix B.

Addition and Subraction of Matrices

To add or subtract matrices, they must be the same size. For example, if I had a 3x3 matrix, I can only add with another 3x3 martrix. To add or subtract, get the first position of the first matrix, and add or subtract to the first position on the second matrix. Do this for all of the positions. You will end up with a new matrix with the addition or subtraction.

alt text alt text

More Information:

Wikipedia