# Matrices

Matrix is a set of elements arranged in a rectangular table of m rows and n columns.

``````    | a11 a12 a13 a14|
A=  | a21 a22 a23 a24|
| a31 a32 a33 a34|
| a41 a42 a43 a44|
``````

## square matrix

Square matrix is a matrix with the same number of rows and columns.

## zero matrix

Zero matrix it is a matrix with all elements equal to zero.

## main diagonal

The main diagonal of a matrix is the diagonal starting from the upper left corner of the matrix.

It is also knows as primary diagonal and major diagonal.

``````    | a11 a12 a13 a14|
A=  | a21 a22 a23 a24|
| a31 a32 a33 a34|
| a41 a42 a43 a44|
``````

## diagonal matrix

Diagonal matrix is a matrix in which the elements outside the main diagonal are all zero. The term usually refers to square matrices.

``````    | a11 0 0 0|
A=  | 0 a22 0 0|
| 0 0 a33 0|
| 0 0 0 a44|
``````

## identity matrix

Identity matrix is a matrix whose elements along the main diagonal are equal to 1, and the rest are 0. It is usually denoted by I.

``````    | 1 0 0 0|
I=  | 0 1 0 0|
| 0 0 1 0|
| 0 0 0 1|
``````

## trace

Trace of a square matrix is the sum of elements on the main diagonal.

## lower triangular matrix

Lower triangular matrix is a square matrix whose elements above the main diagonal are zero.

## upper triangular matrix

Upper triangular matrix is a square matrix whose elements above the main diagonal are zero.

## equality of matrices

Two matrices A and B are equal if aij = bij

## sum of matrices

The sum A+B of two m-by-n matrices A and B will be matrix with elements cij = aij+bij.

A+B = B+A

(A+B)+C = A+(B+C)

## scalar multiplication

The multiplication x*A of real number x and matrix A will be matrix with elements cij = aij*x.

## transposition

The transpose of an m-by-n matrix A is the n-by-m matrix AT formed by turning rows into columns and vice versa: (AT)i,j = Aj,i.

In other words, this is a 90 degree rotation of the matrix.

## matrix multiplication

Multiplication of two matrices is defined if and only if the number of columns of the left matrix is the same as the number of rows of the right matrix.

If A is an m-by-n matrix and B is an n-by-p matrix, then their matrix product AB is the m-by-p matrix whose entries are given by dot product of the corresponding row of A and the corresponding column of B:

``````[A*B]i,j = ai,1*b1,j + ai,2*b2,j + ... + ai,n*bn,j
where 1 ≤ i ≤ m and 1 ≤ j ≤ p
``````

## determinant

The determinant is a scalar value that can be computed from the elements of a square matrix. It is denoted as det(A) or |A|.

second-order determinant (for matrix 2x2):

``````    |a11 a12|
det |a21 a22| = a11*a22 - a21*a12
``````

third-order determinant (for matrix 3x3):

``````        |a11 a12 a13|
det A = |a21 a22 a23| =
|a31 a32 a33|
``````
a11*
``````|a22 a23|
|a32 a33|
``````
- a12*
``````|a21 a23|
|a31 a33|
``````
+ a13*
``````|a21 a22|
|a31 a32|
``````
= a11a22a23 + a12a23a31 + a13a21a32 - a13a22a31 - a11a23a32 - a12a21a33

With this Laplace expansion method, you can compute the determinant of a square matrix of any order. Just follow the next steps:

1. Choose any row or column of A.
2. For each element aij of this row or column, compute the associated cofactor Cij = (-1) i + j* Mij.
1. Remove row and columns that contain aij from matrix. This will give you an n-1 submatrix.
2. Calculate the determinant of this submatrix aka minor (denoted as Mij).
3. Finally, multiply the calculated minor by (-1) i + j and you will get cofactor.
3. Multiply each cofactor by the associated matrix element aij.
4. The sum of these products is det A.

## degenerate matrix

A degenerate matrix, is a square matrix whose determinant is zero.

## inverse matrix

For each non-degenerate matrix of order n, there is an inverse matrix A-1, such that their product is equal to the identity matrix, i.e.

A*A-1 = I

For 2x2 matrix:

```|a b|-1
|c d|```
=
```___1___
*
```|d  -b|
|-c  a|```

If matrix 3x3 represents orthogonal space, than inverse matrix is equal to the transposed matrix.

For other cases you can use the Gauss-Jordan method, which uses elementary row operations. There are also other methods.

## symmetric matrix

A square matrix whose transpose is equal to itself is called a symmetric matrix:

AT = A

## orthogonal matrix

A square matrix whose transpose is equal to its inverse is called an orthogonal matrix:

AT = A-1