Introduction to Vectors#

When describing some quantities, just a number and units aren’t enough. Say we are navigating a ship across the ocean and we are told that the port is 5 km away, we don’t know in which direction we have to sail. 5 km due east would give us all the information we need. This is an example of a vector, a quantity that has magnitude and direction.

  • Some chemistry related vector quantities are velocity, force, acceleration, linear and angular momentum and electric and magnetic fields.

  • Quantities that have just a magnitude are scalars. Examples of these are temperature, mass, and speed.

Vectors in 2-D Space#

A vector in 2-D space can be written as a combination of 2 base vctors, \(\vec{i}\) being a horizontal vector (in the x-direction) and \(\vec{j}\) being in the vertical vector (in the y-direction). They are both unit vectors, meaning that their length (magnitude) is 1. For an example, the vector \(\vec{v} = 2\vec{i} + 3\vec{j}\) is shown below:

Hide code cell source

import numpy as np
import matplotlib.pyplot as plt

v = np.array([2, 3])

fig, ax = plt.subplots()

ax.quiver(0, 0, v[0], v[1], angles='xy', scale_units='xy', scale=1, color='b')
ax.quiver(0, 0, 0, 1, angles='xy', scale_units='xy', scale=1, color='r')
ax.quiver(0, 0, 1, 0, angles='xy', scale_units='xy', scale=1, color='r')
ax.text(v[0]/2, v[1]/2, r'$\vec{v}$', ha='right', va='bottom', color='b')
ax.text(0.2, 0.5, r'$\vec{j}$', ha='right', va='center', color='r')
ax.text(0.5, 0.25, r'$\vec{i}$', ha='center', va='top', color='r')
ax.set_aspect('equal')
ax.set_xlim(-0.5, 3.5)
ax.set_ylim(-0.5, 3.5)

plt.show()
../_images/7df0bea0f52db8fd16617b6e943966a31d3296686d08e00c273b51ba910638cd.png

The vector \(\vec{v}\) above also describes all vector at move \(2\vec{i}\) units and \(3\vec{j}\) units, they don’t have to start at the origin. All the vectors in the graph below are exactly the same.

fig, ax = plt.subplots()

for x, y in [[0, 0], [-4, 1], [0, -3]]:
    ax.scatter([x, v[0]], [y, v[1]], marker='')
    ax.quiver(x, y, v[0], v[1], angles='xy', scale_units='xy', scale=1, color='b')
    ax.quiver(x, y, 0, 1, angles='xy', scale_units='xy', scale=1, color='r')
    ax.quiver(x, y, 1, 0, angles='xy', scale_units='xy', scale=1, color='r')
ax.set_aspect('equal')
ax.set_xlim(-4.5, 4.5)
ax.set_ylim(-4.5, 4.5)

plt.show()
../_images/f0ec1897e0b08f6281dc5e5019c918d626ebab02c9de6fd77f3066fa49b780d9.png

Writing a general 2-D vector \(\vec{u}\) as a combination of the unit vectors would give:

\[ \vec{u}=a\vec{i} + b\vec{j} \]

where \(a\) and \(b\) are real numbers.


In Python, we can represent any vector using a NumPy array. For example, the vector \(\vec{v}\) above can be represented as:

import numpy as np

v = np.array([2, 3])
print(v)
[2 3]

We will use this vector in some examples later.


Vectors in 3-D Space#

Any vector in 3-D space can be written as a combination of 3 base vectors; \(\vec{i}\), \(\vec{j}\), \(\vec{k}\) each being the unit vector in the x-, y-, and z-dimensions. Below is a plot of the 3 axes with their repective unit vectors:

Hide code cell source

ax = plt.figure().add_subplot(projection='3d')

ax.quiver(0, 0, 0, 1, 0, 0, length=1, color='r')
ax.quiver(0, 0, 0, 0, -1, 0, length=1, color='r')
ax.quiver(0, 0, 0, 0, 0, 1, length=1, color='r')

ax.set_xlim3d(-1.5, 1.5)
ax.set_ylim3d(-1.5, 1.5)
ax.set_zlim3d(-1.5, 1.5)

plt.show()
../_images/899749dc82ad0c2a4823e4f985129d205b4afe345704e5f9a94afdabb3377dae.png

Writing a general vector \(\vec{v}\) as a combination of the unit vectors would give:

\[ \vec{v} = a\vec{i} + b \vec{j} + c\vec{k} \]

where \(a\), \(b\), and \(c\) are real numbers.


To extend a NumPy array to 3-D simply involves adding another value, i.e.,

u = np.array([2, 3, 1])
print(u)
[2 3 1]

We can visualise this in a 3-D plot with matplotlib.

ax = plt.figure().add_subplot(projection='3d')

ax.quiver(0, 0, 0, 1, 0, 0, length=1, color='r')
ax.quiver(0, 0, 0, 0, -1, 0, length=1, color='r')
ax.quiver(0, 0, 0, 0, 0, 1, length=1, color='r')
ax.plot([0, u[0]], [0, u[1]], [0, u[2]], color='b')

ax.set_xlim3d(-1.5, 3.5)
ax.set_ylim3d(-1.5, 3.5)
ax.set_zlim3d(-1.5, 3.5)

ax.set_aspect('equal')

plt.show()
../_images/e2eeb313478bb37f2d18ebdcbacf7bc1aaf30b207cfcf53aec3d409547e14831.png

Representations of Vectors#

A vector \(\vec{v}\) can be written in the following forms:

  1. Unit vector notation:

    \[ \vec{v} = a\vec{i} + b\vec{j} + c\vec{k} \]

    The vector is displayed as the clear sum of its base vectors. In 3-D space, those are the \(\vec{i}\), \(\vec{j}\), and \(\vec{k}\) vectors.

  2. Ordered set notation:

    \[ \vec{v} = (a, b, c) \]

    The vector is in the same form as unit vector notation (\(a\), \(b\), and \(c\) are the same numbers) but it is more compact notation.

  3. Column notation:

    \[\begin{split} \vec{v} = \begin{pmatrix} a \\ b \\ c \end{pmatrix} \end{split}\]

    This is identical to ordered set notation apart from it being vertical. This form makes some calculations easier to visualise, such as the dot product.

For example, the 2-D vector \(\vec{u}\) shown below can be written as \(\vec{u} = 4\vec{i} + 3\vec{j}\) or \(\vec{u} = (4, 3)\) or \(\vec{u} = \begin{pmatrix} 4 \\ 3 \end{pmatrix}\).

Hide code cell source

import numpy as np
import matplotlib.pyplot as plt

v = np.array([4, 3])

fig, ax = plt.subplots()

ax.quiver(0, 0, v[0], v[1], angles='xy', scale_units='xy', scale=1, color='b')
ax.text(v[0]/2, v[1]/2, r'$\vec{u}$', ha='right', va='bottom', color='b')
ax.set_aspect('equal')
ax.set_xlim(-0.5, 5.5)
ax.set_ylim(-0.5, 5.5)

plt.show()
../_images/5fc7e9c62aae9f6fb79282866d99420d48a8f0be68c17892c6ec83c79ca1e23e.png

Magnitude of Vectors#

If we know the lengths of each of the component vectors, we can find the length (or magnitude), \(|\vec{v}|\), of the vector using Pythagoras theorem. For a 3-D vector \(\vec{v} = a\vec{i} + b\vec{j} + c\vec{k}\):

\[ |\vec{v}| = \sqrt{a^2 + b^2 + c^2} \]

For vector \(\vec{u} = 4\vec{i} + 3\vec{j}\) above, we can calculate the magnitude \(|\vec{u}| = \sqrt{4^2+3^2} = \sqrt{16+9} + \sqrt{25} = 5\)

Example

Find the magnitude of the following vectors:

  1. \((2, 6, 3)\)

  2. \(\vec{i} + 7\vec{j} + 4\vec{k}\)

  3. \(\begin{pmatrix} \sqrt{2} \\ \sqrt{2} \\ 0 \end{pmatrix}\)

Solution:

  1. \(|(2, 6, 3)| = \sqrt{2^2 + 6^2 + 3^2} = \sqrt{4+36+9} = \sqrt{49} = 7\)

  2. \(| \vec{i} + 7\vec{j} + 4\vec{k} | = \sqrt{1^2 + 7^2 + 4^2} = \sqrt{1 + 49 + 16} = \sqrt{66}\)

  3. \(\left| \begin{pmatrix} \sqrt{2} \\ \sqrt{2} \\ 0 \end{pmatrix} \right| = \sqrt{(\sqrt{2})^2 + (\sqrt{2})^2} = \sqrt{2+2} = \sqrt{4} = 2\)


In Python, we can obtain the magnitude by squaring all the values, summing them, and finding the square root.

np.sqrt(np.sum(np.array([2, 6, 3]) ** 2))
7.0

Or it is possible to use the np.linalg.norm function.

np.linalg.norm(np.array([1, 7, 4]))
8.12403840463596

To show that these are equivalent.

v = np.array([np.sqrt(2), np.sqrt(2), 0])

np.sqrt(np.sum(v ** 2)), np.linalg.norm(v)
(2.0, 2.0)

Helium Velocity

A helium atom is moving with a velocity \(\vec{v}\) of \(20\vec{i} - 15\vec{j}\) ms-1. What is the speed of the atom?

Solution: Since speed is the magnitude of velocity, we take the magnitude of the velocity vector. This gives:

\[ |20\vec{i} - 15\vec{j} | = \sqrt{20^2 + (-15)^2} = \sqrt{625} = 25 \]

Therefore, the particles speed is 25 ms-1.


And with NumPy, this looks like:

v = np.array([20, -15])
np.linalg.norm(v)
25.0