Vector Calculus

Vector Calculus

1. Vectors - Revision

import numpy as np

λ = 5 # real number
a = np.array([1,3,5]) # vector 1
b = np.array([2,4,6]) # vector 2
c = a + b # vector addition
d = λ * a # scalar Multiplication

print(c) # prints [3, 7, 11]
print(d) # prints [5, 15, 25]
How to define vector addition scalar multiplication in Python

import numpy as np

a = np.array([1,3,5]) # vector 1
b = np.array([2,4,6]) # vector 2

a_dot_b =,b) # dot product
print(a_dot_b) # prints 44
How to perform a dot product in Python

import numpy as np
import numpy.linalg as la

b = np.array([3,4,5])  # vector 1
c = np.array([5,8,13]) # vector 2

def mag(vector):
	 magnitude = np.sqrt(,a))
	 return magnitude

magnitude_of_b = mag(b)
print(magnitude_of_b) # 5\sqrt{2}

# Alternatively
magnitude_of_c = la.norm(c)
print(magnitude_of_c) # approx. 16.06
How to define a function that returns the magnitude of a vector in Python

import numpy as np
import numpy.linalg as la

a = np.array([ 1,1,1]) # vector 1
b = np.array([-1,1,1]) # vector 2

def angle(vector1,vector2):
	 v12 =,vector2)
	 # perform dot product
	 v1  = la.norm(vector1,vector1)
	 v2  = la.norm(vector2,vector2)
	 # Mag of each vector 

	 cosine = v12/(v1 * v2)
	 theta = np.arcos(cosine)
	 # return the angle between them

	 return theta

theta_ab = angle(a,b)
print(theta_ab) # approx. 1.23 rads
Defining a simple function that returns the angle between two vectors

import numpy as np

a = np.array([1,3,5]) # vector 1
b = np.array([5,1,3]) # vector 2

a_cross_b = np.cross(a,b)
print(a_cross_b) # [ 4, 22, -16]
Defining the cross product between two vectors in Python

1.1 The connection between vectors and Cartesian coordinates

A vector is a quantity with magnitude and direction. A point AA in space can be labelled by coordinates (a1,a2,a3)(a_{1}, a_{2}, a_{3}) with respect to some Cartesian coordinate frame with the origin defined as O:=(0,0,0)O := (0,0,0) . The distance from OO to PP is

OA=a12+a22+a32|OA|=\sqrt{a_{1}^{2} + a_{2}^{2} + a_{3}^{2}}

Associated with OO and AA is a direction - from OO to AA. One can identify a vector OA\vec{OA} with this direction, which has a magnitude OA|OA|. This vector can also be defined by its coordinates, which is written as

OA=(a1,a2,a3)a\vec{OA}=(a_{1}, a_{2}, a_{3})\equiv \bold{a}

Two vectors, OA=a=(a1,a2,a3)\vec{OA} = \bold{a} = (a_{1},a_{2},a_{3}) and OB=b=(b1,b2,b3)\vec{OB}=\bold{b} = (b_{1},b_{2},b_{3}) can be added together. This creates a new vector whose components are simply the sum of the relevant components of a\bold{a} and b\bold{b}.

a+b=(a1+b1,a2+b2,a3+b3)\bold{a} + \bold{b} = (a_{1}+b_{1}, \:a_{2}+b_{2},\:a_{3}+b_{3})

This is consistent with the parallelogram law of vector addition - see Fig. 1.1. There is also a notion of scalar multiplication: if λR\lambda \in \mathbb{R} and if OA=a=(a1,a2,a3)\vec{OA} = \bold{a} = (a_{1},a_{2},a_{3}), then

λ(OA)=λa=(λa1,λa2,λa3)\lambda(\vec{OA}) = \lambda\bold{a} = (\lambda a_{1},\lambda a_{2},\lambda a_{3})

One can also identify unit vectors (vectors of length one, sometimes you’ll hear this referred to as unity) that point along the three different, mutually perpendicular directions of the Cartesian frame:

x^=(1,0,0),y^=(0,1,0),z^=(0,0,1)\hat{\bold{x}}=(1,0,0),\quad \hat{\bold{y}}=(0,1,0), \quad \hat{\bold{z}}=(0,0,1)

This means one can write a vector as

OA=a=(a1,a2,a3)=a1(1,0,0)+a2(0,1,0)+a3(0,0,1)=a1x^+a2y^+a3z^\vec{OA} = \bold{a} = (a_{1},a_{2},a_{3}) = a_{1}(1,0,0) + a_{2}(0,1,0)+ a_{3}(0,0,1) = a_{1}\hat{\bold{x}}+a_{2}\hat{\bold{y}}+a_{3}\hat{\bold{z}}

which adds further consistency to the identification of triplets of numbers with vectors.

1.2 The dot product

Definition 1.1 Consider two vectors a=(a1,a2,a3)\bold{a} = (a_{1},a_{2},a_{3}) and b=(b1,b2,b3)\bold{b} = (b_{1},b_{2},b_{3}). The dot product is a combination of these two vectors that returns a scalar, and is defined as:

ab:=a1b1+a2b2+a3b3\bold{a}\cdot\bold{b} := a_{1}b_{1} + a_{2}b_{2}+a_{3}b_{3}

The dot product inherits much of the same properties as ordinary multiplication:

  1. Commutative:ab=ba\qquad\bold{a}\cdot\bold{b}=\bold{b}\cdot\bold{a}
  2. Distributive: a(b+c)=ab+ac\qquad\bold{a}\cdot(\bold{b}+\bold{c}) = \bold{a}\cdot\bold{b} + \bold{a}\cdot\bold{c}

for all a\bold{a}, b\bold{b} and c\bold{c} in R3\mathbb{R}^{3}. Here R3\mathbb{R}^{3} denotes all triples (x,y,z)(x,y,z), where xx, yy and zz are real numbers; equivalently, it denotes all points in three-dimensional space.

The dot product can also be used to compute the magnitude of a vector:

mag(a)=a12+a22+a33=aa\mathrm{mag}(\bold{a}) = \sqrt{a_{1}^{2} + a_{2}^{2}+a_{3}^{3}} = \sqrt{\bold{a}\cdot\bold{a}}

From here on the magnitude of a vector will be defined as a|\bold{a}|. Using the properties of the dot-product, the following theorem can be proven:

Theorem 1.1 Let a\bold{a} and b\bold{b} be vectors in R3\mathbb{R}^{3}. Then

ab=abcos(θ)\bold{a}\cdot\bold{b} = |\bold{a}||\bold{b}|\:\mathrm{cos}(\theta)

where 0θπ0\le\theta\le\pi is the angle between a\bold{a} and b\bold{b}.

Proof: Introduce a new vector c:=ab\bold{c}:=\bold{a}-\bold{b} and apply the laws of dot-product multiplication to obtain

cc=(ab)(ab)=aa+bb2abc2=a2+b22ab\bold{c}\cdot\bold{c}=(\bold{a}-\bold{b})\cdot(\bold{a}-\bold{b})\\ \quad\qquad\:\:\:= \bold{a}\cdot\bold{a} + \bold{b}\cdot\bold{b} - 2\:\bold{a}\cdot\bold{b}\\ \quad\:|\bold{c}|^{2} = |\bold{a}|^{2}+|\bold{b}|^{2}-\color{darkseagreen}{ 2\:\bold{a}\cdot\bold{b}}

Referring to the triangle in Fig. 1.2, one can apply the cosine rule for the side length c|\bold{c}| and obtain

c2=a2+b22abcos(θ)|\bold{c}|^{2} = |\bold{a}|^{2}+|\bold{b}|^{2}-\color{darkseagreen}{2\:|\bold{a}||\bold{b}|\:\mathrm{cos}(\theta)}

Comparing this expression with the previous one, the desired result is acquired.

ab=abcos(θ)\therefore\quad\bold{a}\cdot\bold{b} = |\bold{a}||\bold{b}|\:\mathrm{cos}(\theta)

Corollary 1.1 Two vectors a\bold{a} and b\bold{b} are orthogonal (perpendicular) if and only if their dot product is zero

Example: Consider the unit vectors defined earlier, x^\hat{\bold{x}} and y^\hat{\bold{y}}.x^y^=(1,0,0)(0,1,0)=1×0+0×1+0×0=0\hat{\bold{x}}\cdot\hat{\bold{y}}=(1,0,0)\cdot(0,1,0) = 1\times0\:+\:0\times1\:+\:0\times0 = 0

Not surprisingly these vectors have a zero dot product as they point along different mutually-perpendicular axes. The vectors x^\hat{\bold{x}}, y^\hat{\bold{y}} and z^\hat{\bold{z}} are called an orthogonal triad.

1.3 The vector or cross product

In the previous section it was shown how two vectors can form a scalar. In this section it will be shown how two vectors can be used to construct a third.

Definition 1.2 (Cross Product)

a×b=x^y^z^a1a2a3b1b2b3=x^(a2b3a3b2)y^(a1b3a3b1)+z^(a1b2a2b1)\bold{a}\times\bold{b} = \begin{Vmatrix} \hat{\bold{x}} & \hat{\bold{y}} & \hat{\bold{z}}\\ a_{1} & a_{2} & a_{3}\\ b_{1} & b_{2} & b_{3} \end{Vmatrix} =\hat{\bold{x}}(a_{2}b_{3}-a_{3}b_{2}) - \hat{\bold{y}}(a_{1}b_{3} - a_{3}b_{1})+\hat{\bold{z}}(a_{1}b_{2}-a_{2}b_{1})

The double lines either side of the “matrix” just mean that one takes the determinant of this matrix. Its worth mentioning that this isn’t a true matrix since not all elements of the matrix are scalars, the top row are vectors, but this formula treats them as scalars.

Properties of the cross product:

  1. Skew-symmetry: a×b=b×a\quad\bold{a}\times\bold{b} = -\bold{b}\times\bold{a}
  2. Linearity: (λa)×b=a×(λb)=λ(a×b)\quad\qquad(\lambda\:\bold{a})\times\bold{b} = \bold{a}\times(\lambda\:\bold{b}) = \lambda(\bold{a}\times\bold{b})
  3. Distributive: a×(b+c)=(a×b)+(a×c)\quad\quad\bold{a}\times(\bold{b}\:+\:\bold{c}) = \bold{(a\times b) + (a\times c)}

From these properties we can see that :

a×a=a×a2a×a=0a×a=0\begin{align*} \bold{a}\times\bold{a} &= -\bold{a}\times\bold{a}\\ 2\:\bold{a}\times\bold{a}&=0\\ \therefore\quad\bold{a}\times\bold{a}&=0 \end{align*}

Thus it can be deduced that when vectors are parallel their cross product will be zero.

Example: Leta=(1,3,1)&b=(2,1,2)\bold{a}=(1,3,1)\quad\&\quad\bold{b}=(2,-1,2)

Then the cross product is:

a×b=x^y^z^131212=(7,0,7)=7x^7z^\bold{a}\times\bold{b} = \begin{Vmatrix} \hat{\bold{x}} & \hat{\bold{y}} & \hat{\bold{z}}\\ 1 & 3 & 1\\ 2 & -1 & 2 \end{Vmatrix} =(7,0,-7)=7\hat{\bold{x}}-7\hat{\bold{z}}

The orthogonal triad x^\hat{\bold{x}}, y^\hat{\bold{y}} and z^\hat{\bold{z}} satisfy the following:

  1. x^×y^=z^\hat{\bold{x}}\:\times\:\hat{\bold{y}}=\hat{\bold{z}}
  2. y^×z^=x^\hat{\bold{y}}\:\times\:\hat{\bold{z}}=\hat{\bold{x}}
  3. z^×x^=y^\hat{\bold{z}}\:\times\:\hat{\bold{x}}=\hat{\bold{y}}

1.4 Geometrical treatment of the cross product

The definition provided previously for the cross product was in terms of the Cartesian coordinate system, however the cross product is independent of coordinate choice. In this section we re-construct the cross product

First: Finding the magnitude of a×b\bold{a}\times\bold{b}

From the previous section we can note the following

a×b2+(ab)2=(a2b3a3b2)2+(a1b3a3b1)2+(a1b2a2b1)2+(a1b1+a2b2+a3b3)2=(a12+a22+a32)(b12+b22+b32)=a2b2a×b2=a2b2(ab)2=a2b2(1cos2(θ))=a2b2sin2(θ)a×b=absin(θ)\begin{align*} |\bold{a}\times\bold{b}|^{2}+(\bold{a}\cdot\bold{b})^{2} &= (a_{2}b_{3}-a_{3}b_{2})^{2}+ (a_{1}b_{3}-a_{3}b_{1})^{2}+ (a_{1}b_{2}-a_{2}b_{1})^{2}+ (a_{1}b_{1}+a_{2}b_{2}+a_{3}b_{3})^{2}\\ &=(a_{1}^{2}+a_{2}^{2}+a_{3}^{2})(b_{1}^{2}+b_{2}^{2}+b_{3}^{2})\\ &=|\bold{a}|^{2}|\bold{b}|^{2}\\ |\bold{a}\times\bold{b}|^{2} &= |\bold{a}|^{2}|\bold{b}|^{2}-(\bold{a}\cdot\bold{b})^{2}\\ &= |\bold{a}|^{2}|\bold{b}|^{2}(1-\mathrm{cos}^{2}(\theta))\\ &= |\bold{a}|^{2}|\bold{b}|^{2}\mathrm{sin}^{2}(\theta)\\ \therefore\quad |\bold{a}\times\bold{b}| &= |\bold{a}||\bold{b}|\mathrm{sin}(\theta) \end{align*}

Where 0θπ0\le\theta\le\pi

Second: Finding the direction of a×b\bold{a}\times\bold{b}

Similarly from the previous section we can note the following

a(a×b)=a1(a2b3a3b2)+a2(a3b1a1b3)+a3(a1b2a2b1)=0b(a×b)=b1(a2b3a3b2)+b2(a3b1a1b3)+b3(a1b2a2b1)=0\begin{align*} \bold{a}\cdot(\bold{a}\times\bold{b}) & = a_{1}(a_{2}b_{3}-a_{3}b_{2}) + a_{2}(a_{3}b_{1}-a_{1}b_{3}) + a_{3}(a_{1}b_{2}-a_{2}b_{1})=0\\ \bold{b}\cdot(\bold{a}\times\bold{b}) & = b_{1}(a_{2}b_{3}-a_{3}b_{2}) + b_{2}(a_{3}b_{1}-a_{1}b_{3}) + b_{3}(a_{1}b_{2}-a_{2}b_{1})=0\\ \end{align*}

Hence, a×b\bold{a}\times\bold{b} is a vector that is perpendicular to both a\bold{a} and b\bold{b}. It remains to find the sense of a×b\bold{a}\times\bold{b} . This is an arbitrary choice and must be fixed. The right-hand rule is how we fix this (fig. 1.3) Choosing a right handed system means the relations for the orthogonal triad x^\hat{\bold{x}}, y^\hat{\bold{y}} and z^\hat{\bold{z}} are satisfied.

In summary , a×b\bold{a}\times\bold{b} is a vector of magnitude absin(θ)|\bold{a}||\bold{b}|\sin(\theta), that is orthogonal to both a\bold{a} and b\bold{b}, and whose sense is determined by the right hand rule.

1.4.1 The cross product as an area

Consider a parallelogram, whose two adjacent sides are made up of vectors a\bold{a} and b\bold{b} (fig. 1.4). The area of the parallelogram is

Area=(baselength)×(perpendicularheight)=(baselength)bsin(θ)=absin(θ)=a×b\begin{align*} \mathrm{Area} &= (\mathrm{base\:\: length})\times(\mathrm{perpendicular\:\:height})\\ &=(\mathrm{base\:\:length})|\bold{b}|\sin(\theta)\\ &=|\bold{a}||\bold{b}|\sin(\theta)\\ &=|\bold{a}\times\bold{b}| \end{align*}

1.5 The scalar triple product and volume

A scalar can be formed from three vectors a\bold{a} , b\bold{b} and c\bold{c} by combining the dot and cross product as follows


This is the so-called ‘scalar triple product’.

Theorem 1.3 The scalar triple product is equivalent to

a1a2a3b1b2b3c1c2c3\begin{Vmatrix} a_{1} & a_{2} & a_{3}\\ b_{1} & b_{2} & b_{3}\\ c_{1} & c_{2} & c_{3} \end{Vmatrix}

Proof: By brute force.

a(b×c)=(a1x^+a2y^+a3z^)x^y^z^b1b2b3c1c2c3=a1(b2c3b3c2)+a2(b3c1b1c3)+a3(b1c2b2c1)=a1b2b3c2c3a2b1b3c1c3+a3b1b2c1c2a(b×c)=a1a2a3b1b2b3c1c2c3\begin{align*} \bold{a}\cdot(\bold{b}\times\bold{c})&=(a_{1}\hat{\bold{x}}+a_{2}\hat{\bold{y}}+a_{3}\hat{\bold{z}})\cdot \begin{Vmatrix} \hat{\bold{x}} & \hat{\bold{y}} & \hat{\bold{z}}\\ b_{1} & b_{2} & b_{3}\\ c_{1} & c_{2} & c_{3} \end{Vmatrix}\\ &= a_{1}(b_{2}c_{3}-b_{3}c_{2})+a_{2}(b_{3}c_{1}-b_{1}c_{3})+a_{3}(b_{1}c_{2}-b_{2}c_{1})\\ &= a_{1} \begin{Vmatrix} b_{2} & b_{3}\\ c_{2} & c_{3} \end{Vmatrix} - a_{2} \begin{Vmatrix} b_{1} & b_{3}\\ c_{1} & c_{3} \end{Vmatrix} + a_{3} \begin{Vmatrix} b_{1} & b_{2}\\ c_{1} & c_{2} \end{Vmatrix}\\ \therefore\quad \bold{a}\cdot(\bold{b}\times\bold{c}) &= \begin{Vmatrix} a_{1} & a_{2} & a_{3}\\ b_{1} & b_{2} & b_{3}\\ c_{1} & c_{2} & c_{3} \end{Vmatrix} \end{align*}

Now consider a parallelepiped spanned by the vectors a\bold{a} , b\bold{b} and c\bold{c} (Fig. 1.5)

Volumeofparallelepiped=(Perpendicularheight)×(BaseArea)=(acos(φ))(bcsin(θ))=(acos(φ))b×c=a(b×c)\begin{align*} \mathrm{Volume\:\:of\:\:parallelepiped}&=(\mathrm{Perpendicular\:\:height})\times(\mathrm{Base\:\:Area})\\ &= (|\bold{a}|\cos(\varphi))(|\bold{b}||\bold{c}|\sin(\theta))\\ &= (|\bold{a}|\cos(\varphi))|\bold{b}\times\bold{c}|\\ &= \bold{a}\cdot(\bold{b}\times\bold{c}) \end{align*}

Corollary 1.2: Three nonzero vectors a\bold{a} , b\bold{b} and c\bold{c} are considered coplanar if and only if a(b×c)=0\bold{a}\cdot(\bold{b}\times\bold{c}) = 0. This equation only holds if the volume of the parallelepiped spanned by those three vectors is zero, this occurs when the perpendicular height is zero which happens when all three vectors lie within the same plane.

1.6 The vector triple product

Given three vectors a\bold{a} , b\bold{b} and c\bold{c}, we can form a fourth vector


The brackets are important since the cross product is not associative

x^×(x^×y^)=x^×z^(x^×x^)×y^=0×y^=0\begin{align*} \hat{\bold{x}}\times(\hat{\bold{x}}\times\hat{\bold{y}}) &=\hat{\bold{x}}\times\hat{\bold{z}}\\ (\hat{\bold{x}}\times\hat{\bold{x}})\times\hat{\bold{y}} &=0\times\hat{\bold{y}}=0 \end{align*}

Theorem 1.3 The vector triple product satisfies

a×(b×c)=b(ac)c(ab)\bold{a}\times(\bold{b}\times\bold{c}) = \bold{b}(\bold{a}\cdot\bold{c})-\bold{c}(\bold{a}\cdot\bold{b})

Proof: Without loss of generality, we can show this equality is true in a frame where b\bold{b} and c\bold{c} lie in the x-y plane. The idea here is that quantities, such as the above, are frame independent. So we can always rotate to a frame that is more convenient. It is possible to keep it completely general and bash out the above equality by hand but that is quite tedious. So defining the vectors as follows

a=(a1,a2,a3),b=(b1,b2,0),c=(c1,0,0)\bold{a}=(a_{1},a_{2},a_{3}),\quad \bold{b}=(b_{1},b_{2},0),\quad \bold{c}=(c_{1},0,0)

Then Fig. 1.1 The Parallelogram law of vector addition

a×(b×c)=a×(0,0,b2c1)=(a2b2c1,a1b2c1,0)b(ac)=b(a1c1)=(a1b1c1,a1b2c1,0)c(ab)=c(a1b1+a2b2)=(a1b1c1+a2b2c1,0,0)b(ac)c(ab)=(a2b2c1,a1b2c1,0)a×(b×c)=b(ac)c(ab)\begin{align*} \bold{a}\times(\bold{b}\times\bold{c})&= \bold{a}\times(0,0,-b_{2}c_{1})=(-a_{2}b_{2}c_{1},\:a_{1}b_{2}c_{1},\:0)\\ \bold{b}(\bold{a}\cdot\bold{c})&=\bold{b}(a_{1}c_{1})=(a_{1}b_{1}c_{1},\:a_{1}b_{2}c_{1},\:0)\\ \bold{c}(\bold{a}\cdot\bold{b}) &= \bold{c}(a_{1}b_{1}+a_{2}b_{2}) = (a_{1}b_{1}c_{1}+a_{2}b_{2}c_{1},\:0,\:0)\\ \bold{b}(\bold{a}\cdot\bold{c})-\bold{c}(\bold{a}\cdot\bold{b})&= (-a_{2}b_{2}c_{1},\:a_{1}b_{2}c_{1},\:0)\\ \therefore\quad\bold{a}\times(\bold{b}\times\bold{c}) & = \bold{b}(\bold{a}\cdot\bold{c})-\bold{c}(\bold{a}\cdot\bold{b}) \end{align*}

René Descartes, a French philosopher, scientist and mathematician  who is credited with the creation of the Cartesian coordinate system.
René Descartes, a French philosopher, scientist and mathematician who is credited with the creation of the Cartesian coordinate system.
Fig.1.1 The Parallelogram Law for Vector Addition
Fig.1.1 The Parallelogram Law for Vector Addition

2. The Geometry of Lines & Planes

This section shows how vector operations are used to describe lines and planes in three dimensions. These ideas are important as they lay the groundwork for dealing with general (smooth) curved lines and surfaces which can be approximated to arbitrary precision by collections of line segments and planar surfaces.

2.1 The Equation of a line

The problem here is to find the equation of a straight line which passes through two given points AA and BB having position vectors a\vec{a} and b\vec{b} with respect to an origin OO.

The solution is to let r\vec{r} be the position of any point PP on the line through AA and BB

OA+AP=OPa+AP=rAP=ra\vec{OA} + \vec{AP} = \vec{OP} \quad\longrightarrow\quad \vec{a} + \vec{AP} = \vec{r} \quad\longrightarrow\quad \vec{AP}=\vec{r}-\vec{a}


OA+AB=OBa+AB=bAB=ba\vec{OA} + \vec{AB} = \vec{OB} \quad\longrightarrow\quad \vec{a} + \vec{AB} = \vec{b} \quad\longrightarrow\quad \vec{AB}=\vec{b}-\vec{a}

Since AP\vec{AP} and AB\vec{AB} are colinear we can say

AP=tAB=t(ba)r(t)=a+t(ba)\vec{AP} = t\vec{AB}=t(\vec{b}-\vec{a}) \quad\longrightarrow\quad \vec{r}(t)=\vec{a}+t(\vec{b}-\vec{a})

This means that only two vectors are needed to specify a line in space. One vector the lies somewhere on the line r0=a\vec{r}_{0}=\vec{a} and another vector that lies parallel to the line e=ba\vec{e}=\vec{b}-\vec{a}. So we can write the equation of a line


We say that a straight line is a one parameter curve.

3. Ordinary Derivatives of Vectors

4. Frenet-Serret Frame

5. Partial Derivatives & Fields

6. Taylor’s in One and Several Dimensions

7. Gradient, Divergence & Curl

8. Techniques in Vector Differentiation

9. Line Integrals

10. Theory of Integration

11. The Limits of Integration are Not Constants Anymore

12. Integrals Over Surfaces & Volumes

13. Curvilinear Coordinate Systems

14. Special Integrals Involving Curvilinear Coordinates