Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Calculus

Updated: 17 Jul 2026

Derivatives

There are multiple interpretations of what a derivative is:

  1. Geometric: The derivative at a point gives the slope of the tangent line to the curve at that point.

  2. Physical: The derivative represents the instantaneous rate of change, such as velocity being the derivative of position with respect to time.

  3. Analytical: The derivative is defined as the limit of the average rate of change as the interval approaches zero.

Source
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0,2*np.pi,500)
y = 2.3*np.sin(x)
dy_dx = np.gradient(y, x)


i = 70
x0 = x[i]
y0 = y[i]
slope = dy_dx[i]

tangent = y0 + slope * (x - x0)

plt.figure()
plt.plot(x,y)
plt.plot(x,dy_dx,'r--', label='derivative')
plt.plot(x,tangent,'b--',label='tangent')
plt.scatter(x0, y0, zorder=3,label='point of contact')
plt.ylim(-2.5,2.5)
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
# plt.savefig('../derivative.png',dpi=450)
plt.show()
A sine function with both its derivative (a cosine function) and its tangent at a certain point.

Figure 1:A sine function with both its derivative (a cosine function) and its tangent at a certain point.

In general the rate of change at a certain point can be taken using:

ΔyΔx=y(x+Δx)y(x)Δx\frac{\Delta y}{\Delta x}=\frac{y(x+\Delta x)-y(x)}{\Delta x}

and the derivative the limit of Δx0\Delta x \rightarrow 0

dydx=limΔx0y(x+Δx)y(x)Δx\frac{dy}{dx}=\underset{\Delta x \rightarrow 0}{\lim} \frac{y(x+\Delta x)-y(x)}{\Delta x}

We now can calculate the rate of change of a given function, but we can calculate as well the exact value by taking the derivative. Below a list of some standard functions Z(x,y)Z(x,y) and their derivatives with respect to xx. The list is followed by mathematical rules that can be applied to calculate the derivative of more difficult functions.

List of standard derivatives

function (Z(x,y)Z(x,y))derivative (dZdx\frac{dZ}{dx})
x+yx + y1
xyx \cdot yy
xnx^nnxn1n\cdot x^{n-1} (n0n \neq 0)
ecxe^{cx}cecxce^{cx}
nxn^xnxlnnn^x \ln{n}
lnx\ln{x}1x\frac{1}{x}
sinx\sin{x}cosx\cos{x}
cosx\cos{x}sinx-\sin{x}
tanx\tan{x}1+tan2x1+\tan^2{x}

Chain rule

A function with a function f(g(x))f(g(x)) (like sin(x2)\sin(x^2)) can be differentiated using the chain rule:

ddxf(g(x))=f(g(x))g(x)\frac{d}{dx}f(g(x)) = f'(g(x)) \cdot g'(x)

Product rule

A function that is the product of two functions f(x)f(x) and g(x)g(x) can be differentiated using the product rule:

ddx[f(x)g(x)]=f(x)g(x)+f(x)g(x)\frac{d}{dx}[f(x) \cdot g(x)] = f'(x) \cdot g(x) + f(x) \cdot g'(x)

A simple example would be differentiating h(x)=xx2h(x) = x \cdot x^2 where we know this could be written as h(x)=x3h(x) = x^3 and its derivative is h(x)=3x2h'(x) = 3x^2. Using the product rule we get:

h(x)=ddx[xx2]=1x2+x2x=x2+2x2=3x2h'(x) = \frac{d}{dx}[x \cdot x^2] = 1 \cdot x^2 + x \cdot 2x = x^2 + 2x^2 = 3x^2

Quotient rule

The quotient rule is applied when differentiating a function that is the quotient of two functions f(x)f(x) and g(x)g(x): h(x)=f(x)g(x)h(x) = \frac{f(x)}{g(x)}. The derivative is then give by:

h(x)=f(x)g(x)f(x)g(x)[g(x)]2h'(x) = \frac{f'(x) \cdot g(x) - f(x) \cdot g'(x)}{[g(x)]^2}

Summarized

FunctionDerivative
f(x)g(x)f(x)\cdot g(x)f(x)g(x)+f(x)g(x)f'(x)g(x) + f(x)g'(x)
f(x)g(x)\frac{f(x)}{g(x)}g(x)f(x)f(x)g(x)g(x)2\frac{g(x)f'(x)-f(x)g'(x)}{g'(x)^2}
f(g(x))f(g(x))f(g(x))g(x)f'(g(x))g'(x)

Partial derivatives

Above we have only discussed derivatives of functions with one variable. However, many functions depend on multiple variables, e.g. Z(x,y)Z(x,y). In such cases, we can compute the partial derivative with respect to one of the variables, treating the other variables as constants. Consider the function Z(x,y)=x2y+y3Z(x,y) = x^2y + y^3. The partial derivative of ZZ with respect to xx is computed as follows:

Zx=x(x2y+y3)=2xy+0=2xy\frac{\partial Z}{\partial x} = \frac{\partial}{\partial x}(x^2y + y^3) = 2xy + 0 = 2xy

and with respect to yy:

Zy=y(x2y+y3)=x2+3y2\frac{\partial Z}{\partial y} = \frac{\partial}{\partial y}(x^2y + y^3) = x^2 + 3y^2

Noted that in the first year physics course, you will encounter this as well as you often have to deal with uncertainties in multiple quantities. To find the total uncertainty, you will need to compute the partial derivatives of the function with respect to each variable.

Integration

The antiderivative (Dutch: primitieve) of a function f(x)f(x) is the function F(x)F(x) such that F(x)=f(x)F'(x)=f(x).

List of standard antiderivatives

Below is a list of some standard functions and their antiderivative with respect to xx.

function (Z(x)Z(x))antiderivative (Zdx\int Zdx)
xnx^n1n+1xn+1\frac{1}{n+1} x^{n+1} + C (for n1n\neq -1)
1x\frac{1}{x}lnx+C\ln \lvert x \rvert + C
ecxe^{cx}1cecx+C\frac{1}{c}e^{cx} + C
nxn^xnxlnn+C\frac{n^x}{\ln n} + C (for n>0,n1n > 0, n\neq 1)
lnx\ln{x}1x+C\frac{1}{x} + C
sinx\sin{x}cosx+C-\cos{x} + C
cosx\cos{x}sinx+C\sin{x} + C
tanx\tan{x}lnsec(x)+C\ln \lvert \sec(x) \rvert + C [1]

Sum rule

In case where the antiderivative is (or can be) written in the form of two function, the sum rule can be applied:

f(x)+g(x)dx=f(x)dx+g(x)dx\int f(x)+g(x) dx = \int f(x) dx + \int g(x) dx

Product rule

In case of two functions we can make use of the product rule, or integration by parts:

f(x)g(x)dx=f(x)g(x)dxf(x)(g(x)dx)dx+C\int f(x)g(x) dx = f(x)\int g(x)dx - \int f'(x) \left(\int g(x) dx\right) dx +C

Substitution rule

When integrating the product of two functions, we may encounter the special case where one function is (up to a constant factor) the derivative of the other. In this situation, the substitution rule provides a straightforward way to evaluate the integral:

abf(g(x))g(x)dx=g(a)g(b)f(u)du\int_a^b f(g(x)) \cdot g'(x) dx = \int_{g(a)}^{g(b)} f(u) du

Line integrals

We encounter line integrals in the chapter on work. The amount of work done by a force field F\vec{F} when moving an object along a path CC is given by the line integral:

W=CFdrW = \int_C \vec{F} \cdot d\vec{r}

We can visualize this by drawing the force field as arrows in space and the path as a curve. The line integral sums up the contributions of the force along the path, taking into account both the magnitude and direction of the force relative to the path. By looking whether the path goes with or against the force field, we can determine whether the work on the object or by the object.

In a conservative force field, such as gravity or electrostatic forces, the work done is path-independent and only depends on the initial and final positions.

Closed loop integrals

We encounter closed loop integrals in chapter ... There we see that a closed loop integral is the same as a line integral where the start and end point are the same. A closed loop integral is denoted as:

CFdr\oint_C \vec{F} \cdot d\vec{r}

If we use again the idea of a conservative force field, we can see that in such a field the closed loop integral is always zero, as the work done going from point A to point B is exactly canceled out by the work done going back from point B to point A.

Curl, divergence and gradient

For two or three dimensional vector fields, the derivative can apply to all directions. For this, the nabla operator \nabla exists. In three dimensions, the nabla operator is a vector that takes the partial derivative along each coordinate:

=(xyz)\nabla = \begin{pmatrix} \frac{\partial}{\partial x} \\ \frac{\partial}{\partial y} \\ \frac{\partial}{\partial z} \end{pmatrix}

The nabla operator can be applied to a scalar (gradient) or to a vector(field) using the dot or cross product (divergence and curl). We will discuss each of these below.

Note that some of the explanation below is better understood when looking at linear algebra first.

Gradient

We have seen the use of gradient in chapter 3. The gradient of function ff is f\nabla f. It creates a vector that indicates the directions in which ff increases or decreases:

f=(fxfyfz)\nabla f = \begin{pmatrix} \frac{\partial f}{\partial x} \\ \frac{\partial f}{\partial y} \\ \frac{\partial f}{\partial z} \end{pmatrix}

Curl

The curl is used in the chapter on work and energy, specifically in the context of assessing whether a force field is conservative (if so, the path from A to B does not matter on the amount of work that is done). The curl of a vector field F\mathbf{F} is denoted as ×F\nabla \times \mathbf{F}. In mathematical terms, it provides a measure of the rotation (or swirling strength) of the field at a given point. A zero curl indicates that the field is irrotational, which is a characteristic of conservative fields. To get a better conceptual understanding, we can inspect the two fields below. The left is clearly rotating around the center, while the right one is not as all vectors point to the same direction (0,0). Hence, we expect that if we take the curl of the left field, it will be non-zero, while for the right field it will be zero.

Source
import numpy as np
import matplotlib.pyplot as plt

   
def F1(x, y):
    return y, -x

def F2(x, y):
    r = np.sqrt(x**2 + y**2)
    r = np.where(r == 0, 1e-10, r)  # Avoid division by zero
    return -x / r**3, -y / r**3

N = 7
xlim=(-2, 2) 
ylim=(-2, 2)
x = np.linspace(xlim[0], xlim[1], N)
y = np.linspace(ylim[0], ylim[1], N)
X, Y = np.meshgrid(x, y)

Fx1, Fy1 = F1(X, Y)
Fx2, Fy2 = F2(X, Y)
    
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(5, 10))
ax1.quiver(X, Y, Fx1, Fy1)
ax2.quiver(X, Y, Fx2, Fy2)

ax1.set_xlabel("x")
ax1.set_ylabel("y")
ax1.set_xlim(xlim)
ax1.set_ylim(ylim)
ax2.set_xlabel("x")
ax2.set_ylabel("y")
ax2.set_xlim(xlim)
ax2.set_ylim(ylim)
plt.show()

Mathematically, the curl in three dimensions is defined as:

×F=x^y^z^xyzFxFyFz\nabla \times \mathbf{F} = \begin{vmatrix} \hat{x} & \hat{y} & \hat{z} \\ \frac{\partial}{\partial x} & \frac{\partial}{\partial y} & \frac{\partial}{\partial z} \\ F_x & F_y & F_z \end{vmatrix}

where x^\hat{x}, y^\hat{y}, and z^\hat{z} are the unit vectors in the x, y, and z directions, respectively, and FxF_x, FyF_y, and FzF_z are the components of the vector field F\mathbf{F}. Note that the outcome of taking the curl at a point returns a vector (or taking the curl of the vector field results in another vector field).

Divergence

The divergence of a vector field F\mathbf{F} is denoted by F\nabla \cdot \mathbf{F}. It quantifies the magnitude of a source or sink at a given point in the field (e.g. how strong a point is attracting or repelling). A positive divergence indicates a source (where field lines are diverging, such as the electric field E\vec{E}-field around a proton), while a negative divergence indicates a sink (where field lines are converging, such as the electric field E\vec{E}-field around an electron). Mathematically, the divergence in three dimensions is defined as:

F=Fxx+Fyy+Fzz\nabla \cdot \mathbf{F} = \frac{\partial F_x}{\partial x} + \frac{\partial F_y}{\partial y} + \frac{\partial F_z}{\partial z}

where FxF_x, FyF_y, and FzF_z are the components of the vector field F\mathbf{F}. Note that taking the divergence at a point returns a scalar value, not a vector.

Footnotes
  1. sec(x)=1cos(x)\sec(x)=\frac{1}{\cos(x)}