@dxzmpk/js-algorithms-data-structures
Version:
Algorithms and data-structures implemented on JavaScript
64 lines (34 loc) • 2.48 kB
Markdown
# Matrices
In mathematics, a **matrix** (plural **matrices**) is a rectangular array or table of numbers, symbols, or expressions, arranged in rows and columns. For example, the dimension of the matrix below is `2 × 3` (read "two by three"), because there are two rows and three columns:
```
| 1 9 -13 |
| 20 5 -6 |
```

An `m × n` matrix: the `m` rows are horizontal, and the `n` columns are vertical. Each element of a matrix is often denoted by a variable with two subscripts. For example, <i>a<sub>2,1</sub></i> represents the element at the second row and first column of the matrix
## Operations on matrices
### Addition
To add two matrices: add the numbers in the matching positions:

The two matrices must be the same size, i.e. the rows must match in size, and the columns must match in size.
### Subtracting
To subtract two matrices: subtract the numbers in the matching positions:

### Multiply by a Constant
We can multiply a matrix by a constant (the value 2 in this case):

### Multiplying by Another Matrix
To multiply a matrix by another matrix we need to do the [dot product](https://www.mathsisfun.com/algebra/vectors-dot-product.html) of rows and columns.
To work out the answer for the **1st row** and **1st column**:

Here it is for the 1st row and 2nd column:

If we'll do the same for the rest of the rows and columns we'll get the following resulting matrix:

### Transposing
To "transpose" a matrix, swap the rows and columns.
We put a "T" in the top right-hand corner to mean transpose:

## References
- [Matrices on MathIsFun](https://www.mathsisfun.com/algebra/matrix-introduction.html)
- [Matrix on Wikipedia](https://en.wikipedia.org/wiki/Matrix_(mathematics))