## Learning and Applying Mathematics using Computing

### Theory: Vectors

This post is a bit of theory about vectors, ready for more work on our bus scenario.

A lot of the recent posts on this blog (e.g. on drifting, braking) have involved manipulating X and Y speeds. In mathematics, these speeds are termed a two-dimensional vector, written as either (xSpeed, ySpeed), or like this:

$\begin{pmatrix} \text{xSpeed} \\ \text{ySpeed} \end{pmatrix}$

So if our current speed is 3 in the X direction and -4 in the Y direction, we can write this as (3, -4) or $\begin{pmatrix} 3 \\ -4 \end{pmatrix}$. We saw in the drifting post how to form X and Y speeds that move at a given speed and angle. This can be written in mathematical notation as:

$\begin{pmatrix} \text{speed} \times \cos(\text{angle}) \\ \text{speed} \times \sin(\text{angle}) \end{pmatrix}$

In fact, it’s so common that all parts of a vector get multiplied by the same number that mathematicians use a notation whereby the number is moved outside the vector — so this is the same as the above:

$\text{speed} \times \begin{pmatrix} \cos(\text{angle}) \\ \sin(\text{angle}) \end{pmatrix}$

A vector can represent anything where one element is X and one is Y, so it can be a position or a speed or an acceleration.