Intermediate

Vectors

AicademyAicademy
·A-Level Computer Science·AQA 7517·5 min
4.2.8 Vectors

What Is a Vector?

A vector is a mathematical object with two properties: magnitude (size) and direction. Vectors are used to represent quantities such as velocity, displacement, and forces — things where direction matters, not just amount.

In computing, a vector is represented as an ordered list of numbers — one number per dimension:

2D vector:  v = (3, 4)       ← x-component, y-component
3D vector:  v = (1, -2, 5)   ← x, y, z components
n-D vector: v = (v₁, v₂, ..., vₙ)

Geometric interpretation — a 2D vector (3, 4) means "3 units right, 4 units up." The magnitude (length) is calculated using Pythagoras:

In a program, a vector is stored just like a 1D array — or a list in Python:

v ← [3, 4]        // 2D vector
u ← [1, -2, 5]    // 3D vector

Vector Addition and Scalar Multiplication

Vector addition adds corresponding components. Two vectors must have the same number of dimensions to be added.

Example:

Scalar multiplication multiplies every component by a single number (the scalar):

Example:

FUNCTION vectorAdd(a, b)
    result ← []
    FOR i ← 1 TO LEN(a)
        result[i] ← a[i] + b[i]
    NEXT i
    RETURN result
ENDFUNCTION

FUNCTION scalarMult(scalar, v)
    result ← []
    FOR i ← 1 TO LEN(v)
        result[i] ← scalar * v[i]
    NEXT i
    RETURN result
ENDFUNCTION

(Extra context — not required by AQA 7517) Vector addition and scalar multiplication are not explicitly listed in the AQA 4.2.8 spec bullets, but they underpin the dot product and convex combination calculations.

The Dot Product

The dot product (scalar product) of two vectors produces a single number, not a vector. It is defined as:

Worked example:

FUNCTION dotProduct(a, b)
    total ← 0
    FOR i ← 1 TO LEN(a)
        total ← total + a[i] * b[i]
    NEXT i
    RETURN total
ENDFUNCTION

(Extra context — not required by AQA 7517) Geometric meaning: the dot product is related to the angle between the two vectors: . If the dot product is 0, the vectors are perpendicular () — used in 3D graphics, physics simulations, and machine learning.

Convex Combinations

A convex combination of two vectors and is a weighted average that produces a point on the line segment between them.

where , , and .

Key property: the constraint with both non-negative ensures always lies on or between and — never outside the segment.

Worked example — find the midpoint of two 2D vectors:

Setting gives ; setting gives ; any value in between gives an intermediate point.

Application — linear interpolation ("lerp") in computer graphics: smoothly animate a point from position to position by varying from 1 to 0 over time.

Something not quite clicking?

Ask Aica to explain any part of this differently. Free, takes 30 seconds.

Ask Aica

Vectors in Code

Vectors are implemented in code using arrays or lists — one slot per component. All vector operations follow naturally from array indexing.

Representing a 2D game object:

// Position and velocity as 2D vectors
position ← [100, 200]    // x=100, y=200
velocity ← [3, -1]       // 3 units/frame right, 1 up

// Update position each frame
FOR i ← 1 TO 2
    position[i] ← position[i] + velocity[i]
NEXT i

Computing magnitude (length):

FUNCTION magnitude(v)
    sumSquares ← 0
    FOR i ← 1 TO LEN(v)
        sumSquares ← sumSquares + v[i] ^ 2
    NEXT i
    RETURN sumSquares ^ 0.5   // Square root
ENDFUNCTION

(Extra context — not required by AQA 7517) Normalising a vector scales it to magnitude 1 while preserving direction — divide each component by the magnitude. In code: RETURN scalarMult(1 / magnitude(v), v).

Common Exam Mistakes

1. Confusing the dot product result type

The dot product of two vectors is a scalar (a single number), not a vector. Describing it as producing a vector is incorrect.

2. Adding vectors of different dimensions

Vector addition is only defined when both vectors have the same number of components. Adding a 2D vector to a 3D vector is undefined.

3. Getting the convex combination constraints wrong

Both weights must be non-negative and they must sum to 1. Forgetting either condition means the result may lie outside the segment between and .

4. Treating as optional

In a convex combination, is a requirement, not a coincidence. Omitting this constraint in an exam answer loses the mark that distinguishes a convex combination from general linear interpolation.

5. Indexing errors in dot product loops

The dot product sums terms for -dimensional vectors. Starting a loop at index 0 in AQA pseudocode (which uses 1-based indexing) or ending one step early produces an incorrect result.

Generate revision on any topic you study

Type any topic you're studying and Aicademy generates a complete lesson, quiz, and flashcard set — personalised to your level.

Lessons on anything

Structured, level-matched lessons on any topic you study

Practice quizzes

Find out what you actually know before the exam does

Flashcard sets

Lock in key concepts with instant revision cards

Ask Aica

Stuck on something? Get a clear explanation, any time

Prev

Hash Tables and Dictionaries

Next

Graph Traversal: BFS and DFS

Related lessons

6 Slides

Lesson

Arrays and Abstract Data Types

A-Level Computer Science · AQA 7517

10 hours ago