Data structures · A level · AQA 7517 4.2.1.4 · about 25 min
Vectors as lists, functions and arrows; addition, scaling, dot product and convex combination, on the robot's position.
[1 mark]What is the dot product of [2, -1, 3] and [4, 5, 1]?
[1 mark]What does this program print?
u = [2, 5] v = [6, 1] w = [0.5 * u[i] + 0.5 * v[i] for i in range(2)] print(w)
[1 mark]For αu + βv to be a convex combination of u and v, which conditions must hold?
[1 mark]The dot product of two non-zero vectors is 0. What does that tell you?
[1 mark]The vector [2.0, 3.5, -1.0] is a member of which set?
[1 mark]What is the angle, in degrees, between the vectors [1, 0] and [1, 1]?
Two beacons are at u = [40, 20] and v = [-20, 60], in cm from the robot's start (x to the right, y forward). Write these three functions yourself, for vectors of any length, without numpy:
- add(a, b): returns a new list, the vector sum of a and b.
- scale(k, a): returns a new list, the number k times the vector a.
- dot(a, b): returns the dot product of a and b, a single number.
Then print, in this order:
1. u.v = <dot product>, which is a whole number.
2. angle = <angle> degrees, the angle between u and v rounded to a whole number with round(). You will need math.acos, math.degrees and math.sqrt.
3. w = <w>, where w = 0.25u + 0.75v, built with scale and add, printed as a Python list, for example w = [1.0, 2.0].
Finally drive to w: slide sideways by its x component (left if it is negative) and then forward by its y component.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() import math u = [40, 20] v = [-20, 60]
Plan your program here, then type it in and press Run.
w really on the segment between the beacons? Check that w - u is a positive scalar multiple of v - u.[3, 4] is zero. What do they have in common?dot so it takes two vectors stored as dictionaries, where missing indexes mean zero.