# Vectors

## Prerequisites

### Vectors

#### Definition

• Vectors are mathematical objects which represent change.
• They are the complement to coordinates, which represent fixed points.
• They have two properties:
• Direction
• Magnitude (or length)
• They are often written as how much change they apply in each dimension:
• A two dimensional vector that changes 3 in the first dimension and 5 in the second dimension is written as [3, 5]
• When writing a variable which holds a vector, an arrow is placed above its symbol:
LaTeX: \vec a = [3, 5]

#### Vectors in one dimension

• A vector with only one dimension is written as a single value enclosed in a set of square brackets:
• This can also be represented graphically:
• Magnitude:
• The magnitude of a one dimensional vector is simply the absolute value of its only element.
• The vectors [5] and [-5] both have a magnitude of 5
• Direction:
• A one dimensional vector can only have two possible directions: forwards and backwards.
• The vectors [5] and [-5] have the same magnitude but different directions.
• The vectors [-3] and [-5] have different magnitudes but the same direction.

#### Vectors in two dimensions

• A vector with two dimensions is written as a pair of values enclosed in a set of square brackets:
• This can also be represented graphically:
• Magnitude:
• The magnitude of a two dimensional vector can be calculated using the Pythagorean theorem.
• The two components of the vector form two sides of a right triangle.
• The magnitude of the vector is equal to the hypotinuse.
• For example:
• If we apply the Pythagorean theorem:

#### Vectors in more than two dimensions

• Vectors can be defined in as many dimensions as desired.
• For example, a 5 dimensional vector would look like this:
• Magnitude:
• To calculate the magnitude of a vector with n dimensions we use the following formula:
• For example, the magnitude of: is

#### code (Python)

In python, vectors are represented as arrays.

import math
import numpy as np

vector = [3, 6, 2]

magnitude = math.sqrt(np.dot(vector, vector))
print(magnitude) # prints: 7.0