# User:Saul/matrices

Matrices are a way of representing complex numbers, usually consisting of a multi-dimensional array of numbers.

Below is an example of the matrix 'A' which is a 3x3 matrix consisting of the numbers a-i.

a | b | c |

d | e | f |

g | h | i |

## Contents

## Addition and Subtraction

To add or subtract two matrices you must first ensure they are both the same size.

For example to calculate the following matrices: A_{NxM} + B_{QxR} you must ensure that N == Q and M == R.

a | b | c |

d | e | f |

g | h | i |

j | k | l |

m | n | o |

p | q | r |

a+j | b+k | c+l |

d+m | e+n | f+o |

g+p | h+q | i+r |

a | b | c |

d | e | f |

g | h | i |

j | k | l |

m | n | o |

p | q | r |

a-j | b-k | c-l |

d-m | e-n | f-o |

g-p | h-q | i-r |

### Example

1 | 0 | 5 |

1 | 3 | 7 |

5 | 9 | 2 |

5 | 5 | 5 |

1 | 8 | 1 |

9 | 1 | 7 |

6 | 5 | 10 |

2 | 11 | 8 |

14 | 10 | 9 |

1 | -2 | 3 |

3 | -2 | 1 |

-7 | 5 | -6 |

7 | 5 | 6 |

-3 | -9 | -7 |

0 | 0 | 9 |

-6 | -7 | -3 |

6 | 7 | 8 |

-7 | 5 | -15 |

## Multiplication

Matrices can by multiplied scaly quantities or other matrices. Matrices multiplication is not communal - A_{N x M} x B_{Q x R} != B_{Q x R} x A_{N x M}

### Scalar

Multiplying a matrix by a scalar value multiplies all values within the matrix by that value.

a | b | c |

d | e | f |

g | h | i |

Za | Zb | Zc |

Zd | Ze | Zf |

Zg | Zh | Zi |

#### Example

1 | 4 | 8 |

2 | 5 | 0 |

9 | -5 | 3 |

4 | 16 | 32 |

8 | 20 | 0 |

36 | -20 | 12 |

### Other Matrices

Multiplying a matrix by another matrix requires you to multiply each value in the row of the first matrix by the corresponding value in the second value's column and sum the total and put it in the position of that row and column, rinse and repeat for the other rows of the first matrix and the columns of the second.

To multiply two matrices together the rows in the first one must be the same amount of the columns in the second matrix.

A_{N x M} x B_{Q x R} can only be done if **M** and **Q** are equal.

B_{Q x R} x A_{N x M} can only be done if **R** and **N** are equal.

The size of the resulting matrix will have the amount of rows the first matrix has and the columns of the second.

A_{N x M} x B_{Q x R} = C_{N x R}

B_{Q x R} x A_{N x M} = C_{Q x M}.

a | b | c |

d | e | f |

g | h | i |

j | k | l |

m | n | o |

p | q | r |

aj + bm + cp | ak + bn + cq | al + bo + cr |

dj + em + fp | dk + en + fq | dl + eo + fr |

gj + hm + ip | gk + hn + iq | gl + ho + ir |

#### Example

1 | 7 |

4 | 0 |

-5 | 3 |

7 | -3 | 5 | 6 |

-1 | 6 | 1 | 6 |

1x7 + 7x-1 | 1x-3 + 7x6 | 1x5 + 7x1 | 1x6 + 7x6 |

4x7 + 0x-1 | 4x-3 + 0x6 | 4x5 + 0x1 | 4x6 + 0x6 |

-5x7 + 3x-1 | -5x-3 + 3x6 | -5x5 + 3x1 | -5x6 + 3x6 |

0 | 39 | 12 | 48 |

28 | -12 | 20 | 24 |

-38 | 33 | -22 | -30 |

## Identity

Identity matrix in complex numbers is the similar to '1' in real numbers.

For example in real numbers: **Y x 1 = Y**

In matrices: **A _{n x n} x I_{n x n} = A_{n x n}** - where

**I**is an identity matrix.

_{n x n}Identity matrices are communal -

**A**

_{n x n}x I_{n x n}= I_{n x n}x A_{n x n}### Examples

1 |

1 | 0 |

0 | 1 |

1 | 0 | 0 |

0 | 1 | 0 |

0 | 0 | 1 |

And so on.

## Inverse

An inverse matrix is a matrix to the power of -1, the same way that the inverse of a scalar number is 1 divided by it - which is same as multiplying by that number to the power of -1, for example: (1/6 = 6^{-1})

So to switch a matrix to the other side of an equation multiply the other side by the inverse and the first side will cancel, for example:

**Ax = y**

(Where A is a matrix)

**A ^{-1}Ax = yA^{-1}**

**x = yA**

^{-1}### Finding the Inverse

#### n x n (Gauss–Jordan Elimination)

To find the inverse of a square matrix of any size (n x n) you can use Gauss–Jordan Elimination.

Start by augmenting the matrix with the identity matrix of the same size then apply row operations till the matrix looks like identity, then the other one will become the inverse.

##### Augment Matrix with Identity

Create an augmented matrix with the matrix (A) and identity (I).

**[A | I]**

###### Example

1 | 4 | 8 |

2 | 5 | 0 |

9 | -5 | 3 |

1 | 0 | 0 |

0 | 1 | 0 |

0 | 0 | 1 |

1 | 4 | 8 | 1 | 0 | 0 | |

2 | 5 | 0 | 0 | 1 | 0 | |

9 | -5 | 3 | 0 | 0 | 1 |

##### Apply Row Operations

Now you need to apply row operations until the matrix (A) becomes Identity (I).

This is best done by:

- Create a lower triangular matrix.
- Create an upper triangular matrix.
- Multiply or divide the rows so the number becomes 1.

**[A | I] → [I | A ^{-1}]**

###### Example - Lower Triangle

0 | -3 | -2 | 1 | 0 | 0 | |

1 | -4 | -2 | 0 | 1 | 0 | |

-3 | 4 | 1 | 0 | 0 | 1 |

**R**

_{1}←→ R_{3}-3 | 4 | 1 | 0 | 0 | 1 | |

1 | -4 | -2 | 0 | 1 | 0 | |

0 | -3 | -2 | 1 | 0 | 0 |

**3R**

_{2}→ R_{2}-3 | 4 | 1 | 0 | 0 | 1 | |

3 | -12 | -6 | 0 | 3 | 0 | |

0 | -3 | -2 | 1 | 0 | 0 |

**R**

_{1}+ R_{2}→ R_{2}-3 | 4 | 1 | 0 | 0 | 1 | |

0 | -8 | -5 | 0 | 3 | 1 | |

0 | -3 | -2 | 1 | 0 | 0 |

**-8R**

_{3}→ R_{3}-3 | 4 | 1 | 0 | 0 | 1 | |

0 | -8 | -5 | 0 | 3 | 1 | |

0 | 24 | 16 | -8 | 0 | 0 |

**3R**

_{2}+ R_{3}→ R_{3}-3 | 4 | 1 | 0 | 0 | 1 | |

0 | -8 | -5 | 0 | 3 | 1 | |

0 | 0 | 1 | -8 | 9 | 3 |

###### Example - Upper Triangle

-3 | 4 | 1 | 0 | 0 | 1 | |

0 | -8 | -5 | 0 | 3 | 1 | |

0 | 0 | 1 | -8 | 9 | 3 |

**5R**

_{1}→ R_{1}-15 | 20 | 5 | 0 | 0 | 5 | |

0 | -8 | -5 | 0 | 3 | 1 | |

0 | 0 | 1 | -8 | 9 | 3 |

**R**

_{1}+ R_{2}→ R_{1}-15 | 12 | 0 | 0 | 3 | 6 | |

0 | -8 | -5 | 0 | 3 | 1 | |

0 | 0 | 1 | -8 | 9 | 3 |

**5R**

_{3}+ R_{2}→ R_{2}-15 | 12 | 0 | 0 | 3 | 6 | |

0 | -8 | 0 | -40 | 48 | 16 | |

0 | 0 | 1 | -8 | 9 | 3 |

**(2/3)R**

_{1}→ R_{1}-10 | 8 | 0 | 0 | 2 | 4 | |

0 | -8 | 0 | -40 | 48 | 16 | |

0 | 0 | 1 | -8 | 9 | 3 |

**R**

_{1}+ R_{2}→ R_{1}-10 | 0 | 0 | -40 | 50 | 20 | |

0 | -8 | 0 | -40 | 48 | 16 | |

0 | 0 | 1 | -8 | 9 | 3 |

###### Example - Simplify

-10 | 0 | 0 | -40 | 50 | 20 | |

0 | -8 | 0 | -40 | 48 | 16 | |

0 | 0 | 1 | -8 | 9 | 3 |

**(-1/10)R**

_{1}→ R_{1}1 | 0 | 0 | 4 | -5 | -2 | |

0 | -8 | 0 | -40 | 48 | 16 | |

0 | 0 | 1 | -8 | 9 | 3 |

**(-1/8)R**

_{2}→ R_{2}1 | 0 | 0 | 4 | -5 | -2 | |

0 | 1 | 0 | 5 | -6 | -2 | |

0 | 0 | 1 | -8 | 9 | 3 |

##### Extract the Inverse

The matrix on the right will become the inverse - so just extract it.

###### Example

1 | 0 | 0 | 4 | -5 | -2 | |

0 | 1 | 0 | 5 | -6 | -2 | |

0 | 0 | 1 | -8 | 9 | 3 |

1 | 0 | 0 |

0 | 1 | 0 |

0 | 0 | 1 |

4 | -5 | -2 |

5 | -6 | -2 |

-8 | 9 | 3 |

#### 2x2

The formulae for finding the inverse of a 2x2 matrix is:

a | b |

c | d |

d | -c |

-b | a |

##### Further Explanation:

The inverse of a 2x2 matrix can be found via:

**A ^{-1} = (1 / Det(A)) * A_{S}**

(Where

**A**is a 2x2 matrix and

**Det(A)**is the Determinant of

**A**and

**A**is the

_{S}*swapped matrix*)

#### 3 x 3 (Determinant Method)

a | b | c |

d | e | f |

g | h | i |

##### Determinants

Take the determinants of each value and input them in place of that value, **making every second one the negative value of this**.

det(e,f,h,i) | -det(d,f,g,i) | det(d,e,g,h) |

-det(b,c,h,i) | det(a,c,g,i) | -det(a,b,g,h) |

det(b,c,e,f) | -det(a,d,c,f) | det(a,b,d,e) |

Expand **det**:

ei - fh | -(di - fg) | dh - eg |

-(bi - ch) | ai - cg | -(ah - bg) |

bf - ce | -(af - dc) | ae - bd |

Expand brackets:

ei - fh | -di + fg | dh - eg |

-bi + ch | ai - cg | -ah + bg |

bf - ce | -af + dc | ae - bd |

Rearrange:

ei - fh | fg - di | dh - eg |

ch - bi | ai - cg | bg - ah |

bf - ce | dc - af | ae - bd |

##### Reflection

Then the matrix must be reflected along the **y=-x** axis:

ei - fh | ch - bi | bf - ce |

fg - di | ai - cg | dc - af |

dh - eg | bg - ah | ae - bd |

#### Checking

To check if a matrix is an inverse multiply it by the normal matrix and the result should be Identity matrix.

For example: **A*A ^{-1}=I**

4 | 7 |

2 | 6 |

0.6 | -0.7 |

-0.2 | 0.4 |

1 | 0 |

0 | 1 |

#### Determinant

Determinant can be notated **det A**, **det(A)** and **|A|**

##### 2x2

The determinant can be calculated by multiplying the top right element by the bottom left subtracted from the product of the top left and bottom right elements.

If the determinant is **0** then the matrix has no inverse.

For example:

a | b |

c | d |

**Det(A)** = **(a * d) - (b * c)**

##### 3x3

Finding the determinate of a 3x3 is a little harder you need to create and find the determinate of 3 2x2 matrices embedded in it.

For example take the following matrix:

a | b | c |

d | e | f |

g | h | i |

You need to select the first number (**a**) and block out all the numbers to the left, right, top and bottom of it (like where a rook could move in chess) like so:

a |
⬛ | ⬛ |

⬛ | e | f |

⬛ | h | i |

Multiply the selected number with the determinate of the other 4 **sitting as they are**:

**a * det(e, f, i, h) = a(ei - fh)**

Do the same for the entire top row and add them together, but **take the negative value of every second one** like so:

**det(A) = a(ei - fh) + (-b(di - fg)) + c(dh - eg)**

## Singular

A singular matrix is a matrix that has no inverse, the same way in scalar numbers **0** has no inverse as you cannot divide by 0.

If the determinant of a matrix is **0** then that matrix has no inverse.

## Transformations

A matrix can be transformed in many ways, most useful to alter a shape that is defined by a set of points.

A point defined as a coordinate can be defined as a matrix:

x |

y |

Once you have your point as a matrix it can be multiplied by another to perform certain transformations on it.

### Translation

### Rotation

A object can be rotated by multiplying the points (matrices) that form that object by another matrix.

The points will be rotated around the origin as its pivot point.

The matrix you need to multiply by is:

cos(A) | -sin(A) |

sin(A) | cos(A) |

Where **A** is the angle to rotate by.

#### Example

To rotate a point **(x, y)** by **36** degrees:

cos(36) | -sin(36) |

sin(36) | cos(36) |

0.81 | -0.59 |

0.59 | 0.81 |

0.81 | -0.59 |

0.59 | 0.81 |

x |

y |

0.81x + -0.59y |

0.59x + 0.81y |

The point **(x, y)** rotated by **36** degrees would be **(0.81x + -0.59y, 0.59x + 0.81y)**:

### Reflection

An object can be reflected along a mirror line. The mirror line is usually drawn at an angle to the X axis. To reflect an object by a mirror line that has an angle of 36deg.

cos(2 * 36) | sin(2 * 36) |

sin(2 * 36) | -cos(2 * 36) |

0.31 | 0.95 |

0.95 | -0.31 |

### Scale

### Multi Transformations

You can apply a transformation to a point (**P**) represented by a matrix (**A**) by multiplying it.

X |

Y |

**P * A**

You can combine transformations by multiplying them together and apply it to the point (**P**) like so:

For transtformations **T _{1}**,

**T**and

_{2}**T**

_{3}**PT**

_{1}T_{2}T_{3}= P_{Transformed by 1, 2 and 3}## Systems of Linear Equations

Matrices are often used to solve more complicated systems of linear equations.

There are two main methods:Gaussian elimination (similarly there is also Gauss-Jordan elimination) and using inverse matrices.

### Using Gaussian

Take the following series of equations:

```
2x + y - z = 1
x + y + 3z = 0
y + z = 1
```

This can be represented as a augmented matrix like so:

2 | 1 | -1 | 1 | |

1 | 1 | 3 | 0 | |

0 | 1 | 1 | 1 |

Then use row operations to create a the lower triangle like so:

2 | 1 | -1 | 1 | |

1 | 1 | 3 | 0 | |

0 | 1 | 1 | 1 |

**2R**

_{2}→ R_{2}2 | 1 | -1 | 1 | |

2 | 2 | 6 | 0 | |

0 | 1 | 1 | 1 |

**R**

_{2}- R_{1}→ R_{2}2 | 1 | -1 | 1 | |

0 | 1 | 7 | -1 | |

0 | 1 | 1 | 1 |

**R**

_{3}- R_{2}→ R_{3}2 | 1 | -1 | 1 | |

0 | 1 | 7 | -1 | |

0 | 0 | -6 | 2 |

Then take the data back out of the matrix and put it back into equation form:

```
2x + y - z = 1
y + 7z = -1
-6z = 2
```

Then solve starting at the bottom working upwards:

```
z = 2 / -6 = -1/3
y + 7(-1/3) = -1
y - (7/3) = -1
y = 4/3
2x + (4/3) - (-1/3) = 1
2x + (5/3) = 1
2x = -2/3
x = -2/6 = -1/3
```

Therefore the solutions are: **x=-1/3, y=4/3, z=-1/3**

### Using Inverse Matrices

Take the following series of equations:

```
2x + y - z = 1
x + y + 3z = 0
y + z = 1
```

This can be represented by the following matrices:

2 | 1 | -1 |

1 | 1 | 3 |

0 | 1 | 1 |

x |

y |

z |

1 |

0 |

1 |

This can be shown as the following equation:

**AX=C**

To solve find the inverse of Matrix **A** and add it to the **BEGINNING** of both sides of the equation:

**A ^{-1}AX=A^{-1}C**

Simplify:

**X=A**

^{-1}CAnd convert back to matrix form:

x |

y |

z |

1/3 | 1/3 | -2/3 |

1/6 | -1/3 | 7/6 |

-1/6 | 1/3 | -1/6 |

1 |

0 |

1 |

Multiply out the last two matrices:

x |

y |

z |

-1/3 |

4/3 |

-1/3 |

Therefore the solutions are: **x=-1/3, y=4/3, z=-1/3**