# Algebra/Vectors in two dimensions

Imagine an arrow that has its tail at the origin <0,0> (the carrots denote a vector) and its head at some coordinate <x,y>. These coordinates are known as the x-component and y-component, respectively. This is a vector: it has a magnitude and direction:
* Magnitude is simply the length of the vector as defined by Pythagorean's Theorem. Hence, the length of any vector is simply √(x$^2$ + y$^2$)
* Direction is the angle the vector is pointing. If the vector is pointing along the positive x-axis, then the angle is 0˚ (0 radians). If it is pointing along the negative x-axis, then the angle is 180˚ (π radians). If it points along the positive y-axis, the angle is 90˚ (π/2 radians), and if it points along the negative y-axis, the angle is 270˚ (3π/2 radians).
    Indented line *Because of trigonometry, we can figure out that x
Following this reasoning, the angle along the positive x-axis is also 360˚ (2π radians), and the angle along the positive y-axis is also 450˚ (5π/2 radians), etc. Similarly, the angle along the negative y-axis is -90˚ (-π/2 radians) and the angle along the negative x-axis is -180˚ (-π radians), etc. Calculating direction is more difficult than calculating magnitude. More on this in a moment.
Interestingly, the x and y components can be calculated by knowing the magnitude, direction, and some trigonometric identities.
* x = (Magnitude) • cos (Direction)
* y = (Magnitude) • sin (Direction)
Returning to direction: given the above equations and the equation for magnitude, we can solve for a vectors direction mathematically by solving the system:
* (Magnitude) = √(x$^2$ + y$^2$)
* x = (Magnitude) • cos (Direction)
* y = (Magnitude) • sin (Direction)
Hence,
* x = √(x$^2$ + y$^2$) • cos (Direction)
* y = √(x$^2$ + y$^2$) • sin (Direction)
Therefore,
* x/√(x$^2$ + y$^2$) = cos (Direction)
* y/√(x$^2$ + y$^2$) = sin (Direction)
Finally,

### Calculating Direction - Example

Let's say we have a vector <√3,1> and we wish to find the direction of it. First, we calculate the magnitude:
* (Magnitude) = √(x$^2$ + y$^2$)
* (Magnitude) = √((√3)$^2$ + (1)$^2$)
* (Magnitude) = √(3 + 1)
* (Magnitude) = √(4)
* (Magnitude) = 2
Then, we can calculate direction:
* Direction = arccos(x/√(x$^2$ + y$^2$)) = arcsin(y/√(x$^2$ + y$^2$))
* Direction = arccos(√(3)/2) = arcsin(1/2)
Using degrees and the arccos equation, we find that direction can be 30˚, or 330˚. Using the arcsin equation, we find that direction can be either 30˚ or 150˚. The common direction is 30˚, so we know this is the direction of the vector. Vector Addition Like numbers (scalars), vectors can be added and subtracted. For vectors you simply add each of the component parts. Subtraction works the same way Hence:
* <5,2> + <-7,4> = <-2,6>
* <5,2> - <-7,4> = <12,-2>

### Scalar Multiplication

If you multiply a scalar by a vector, you simply multiply each of the components by that scalar:
* 3•<5,2> = <15,6>
* -2•<-7,4> = <14,-8>

### Dot Product

You can't multiply two two-dimensional vectors together, but you can take the dot product. To do this, you take the sum of each of the corresponding components' products:
* <5,2>•<-7,4> = (-35) + (8) = -27
* <7,4>•<3,8> = (21) + (32) = 53
It turns out that this has numerous applications.