AS/A Computer Science: Fundamentals of data structures

Representing vectors

A vector can be expressed in a number of ways.

One way is as a series of numbers in a list or array e.g. [2.0,-1.5,1.5]

Another way is as a function e.g.
S ↦ ℝ4
0 ↦ 2.4
1 ↦ 6.8
2 ↦ 4.5
3 ↦ 9.2
This means we have a vector S which is a 4-vector over ℝ. This means there are 4 elements in the vector and each element comes from the set of real numbers. These can be effectively represented by a dictionary as seen below where each element in the vector maps to its value.

dictS = {0:2.4, 1:6.8, 2:4.5, 3:9.2}

A final that we can represent 1, 2 and 3-vectors is as a geometric point in space. A one vector would be a single point on a single axis. A 2-vector would locate a point in 2D space and a 3-vector locates a point in 3D space.

Maths of vectors

A 2-vector conveys both magnitude, via it's length and direction. Larger vectors with more dimensions can convey more spatial information e.g. force or acceleration.

We can add two 2-vectors by adding the x and y values separately. You can add vectors of any size as long as they have the same number of elements. As you can see this si the same as starting the second vector at the finishing point of the first.

We can also subtract a vector from another. This is the same as adding the inverse of the second vector.

We can scale a vector by multiplying each value in the vector by the scaling factor. The image below shows a vector scaled by a factor of 2 meaning that each element in the vector has been multiplied by 2.

Convex combination of two vectors

The convex combination of two vectors tells us that any vector that follows this expression will fall on a line that connects the tips of the two vectors. The expression for the convex combination of vectors is:

αu + &betav
Where:
u and v are each vectors
α + β = 1
and α and β are each greater than or equal to 0.
E.g. 0.5(2,5) + 0.5(4,3) = (1,2.5) + (2,1.5) = (3,4)

Dot product of two vectors

A dot product is an operation on two vectors that results in a scalar value rather than another vector. The dot product of two vectors can be found by multiplying the items in the corresponding positions in each vector and then adding the results. The formula for calculating a dot product of two vectors is:
u.v = (u1 x v1) + (u2 x v2) + ... + (un x vn)e.g.
If a = (2,-1,3) and b = (3,2,1)
a.b = (2 x 3) + (-1 x 2) + (3 x 1) = 6 + -2 + 3 = 7

Applications of dot product

The dot product can be used in calculating the angle between two vectors.
This is because cosθ = (a.b)/(|a|.|b|)
Where a.b is the dot product of the vectors a and b and |a|. |b| means the magnitude of vector a multiplied by the magnitude of vector b.

You don't need to be able to calculate it, just know it is a use of dot product. If you are interested, the magnitude of a vector is the square root of the sum of the squares of the elements.

Knowledge check


Questions:
Correct:

Question text


© All materials created by and copyright S.Goff