We are learning ...- About vector representation
- About vector operations and applications
So that we can ...- Be familiar with the concept of a vector and how to specify them
- Dictionary representation - List representation - 1-D array representation - Visualising a vector as an arrow - Perform vector addition and scalar-vector multiplication
- Perform convex combination of two vectors, u and v
- Perform dot or scalar product of two vectors
- Application of dot product
Data structures are fickle. They are what they are, or rather what they need to be. If a particular data structure represents or models a system which behaves like one thing, then the data structure represents that thing. It's your choice as a programmer which 'container' you wrap around your data depending on what you are required to do with it. The operations which are available to the data structure make it behave in different ways.
Vectors find application in all sorts of fields. You might have met them in maths or physics where they represent a point in space, a force or a direction of travel. They also find application in navigation, weather prediction, engineering, computer science, game design and economics.
The strange thing is that they
look like regular arrays / lists but they don't behave like them.When we write vectors, they are always represented by a letter with an arrow over the top. For instance ...
A vector is a one-dimensional dynamic array (the computer scientists view)Here is a list ...
- As far as we (the programmer) are concerned the term vector and array are
*basically*the same thing (unless you program in a language with native vector support) and can be used interchangeably when programming. - Classically, 'arrays' are defined as fixed size (i.e. static) areas of memory whereas vectors are 'containers' which can change in magnitude, growing and shrinking as required.
- Both arrays and vectors are homogeneous - they can contain only one data type.
- Vector data structures are
*always*one dimensional. A zero-dimensional arrays is called a*scalar*and a multi-dimensional array is often referred to as a*matrix*.
Vector data structures also have different built in methods to a standard array so we can perform special vector operations on them. Before we learn about them, let's have a go at making some vectors.
A vector is an object with both direction and magnitude (the physicists view)In our 3 dimensional, Euclidean world, we can represent vectors in a vector space which have both a
magnitude and a direction (a Euclidean vector). Representing vectors as arrows in this way is familiar to us in our studies in physics and coordinate geometry.
Length of a vectorThe length of a vector (the distance between the vector space origin (0,0) and the vector) is simply calculated using good ole' Pythagorean theorem. Nice! The length of the vector is also known as it's
magnitude or norm and is denoted by the double double vertical bar symbol (see below, in the task).Good Old Pythagoras! He's a lad.
Vector as member of a vector space (the mathematicians view)Everything that physics calls a vector is also a vector in mathematics. But there are things that mathematicians call vectors which physicists wouldn't. Nevertheless, all vectors occupy a
vector space of one or more dimensions. In the mathematical sense, the elements of the vector do not necessarily correspond to positions in our 3D Euclidean vector space (i.e. do not represent magnitude and direction) but they still behave mathematically in the same way.Vectors in the mathematical sense are more abstract.
The whole point of vectors is that they have particular mathematical behaviour ...
*Vector addition*achieves__translation__(moving the vector in it's vector space)*Scalar multiplication*achieves__scaling__(increasing the 'size' of the vector in it's vector space)*Dot / scalar product*(used to determine the__angle__between two vectors)*Convex combination*(used to draw the__minimum bounding polyhedron__between vectors viewed as points).
Vector additionOK - here is another video ('cause Sal Khan explains it so much better than me!) from Khan Academy. Whilst you are watching the video, take some notes in your notebooks.
Adding vectors (7:11)
Python doesn't come with any vector operations built in. If you create two lists with Python and add them together, even though they look like vectors,
they do not behave like vectors. Consider the following task ...
Scalar multiplicationOne more video by Sal! You have to watch the video carefully, although I truly believe that this man is legend and you really won't even realise you are listening, or learning. He repeats himself a lot, but that's good!
Multiplying a vector by a scalar (5:43)
Better had then!
Dot / scalar product (algebraic and geometric)The dot / scalar product of two vectors can, amongst other things, be used to ...
- Determine an scalar product of two vectors;
- Determine whether two vectors are parallel;
- Find the angle between two vectors.
The algebraic dot / scalar product is calculated by finding the sum of all the products of the like terms in the vectors concerned, shown algebraically like this ...The algebraic dot / scalar product always results in a scalar. The value of the scalar is more often used to find the angle between the two vectors but can have uses of it's own. The dot product is a measure of 'how much' of two vectors point in the same direction - how well they are aligned or the component of one vector that acts in the same direction as another. The dot product could be used in the following situations ...- Mechanical work is the dot product of force and displacement vectors (physics);
- Fluid flow through a metal ring / magnetic flux (physics);
- Calculating the resultant cost of my shopping (not physics).
Did you see anything interesting in the results of the exercise? You should have found that some of the dot products you calculated were positive, some were negative and some were zero and the value changes depending on the angle between the vectors. The magnitude of the dot product clearly depends on the angle to which the vectors are aligned.Geometrically, therefore, we can say that ... - Dot product
**> 0**indicates an**acute**angle between the vectors; - Dot product
**= 0**indicates the vectors are**orthogonal**(at right angles). - Dot product
**< 0**indicates an**obtuse**angle between the vectors;
We can also work out the actual angle between the vectors as well. If you are interested, it can be shown that the dot product of two vectors is related to the angle between the vectors by the following expression ...But what does this mean and how do I use it? Well ...
Convex combinationsFinding the points on, inside or outside a line which lies between two vectors. This finds applications in the generation of a 'convex hull' - the smallest polyhedra that contains all the points in a set of points. This really is getting complicated, I wonder whether one final worksheet will help ...
Convex combinations (or convex hulls as they generate) can be used in games programming and route finding.
How about these?
- Using vector maths in game design from Unity3D. This includes details on a different type of vector product (the cross product) and it's application to game design.
- I would really suggest that if you are interested, you watch the Vectors and Spaces course on Khan Academy. It will explain lots of the derivations of different vector algebra rules like Dot Product.
- There is one other type of vector operation that we haven't covered which is called the cross-product. Do some research and find out how it is calculated and what it can be used for (the Unity3D video is helpful here).
END OF TOPIC ASSESSMENT |