Skip to main content
This material has been adapted from material by Fergus Cooper and others from the "Essential Mathematics" module at the Doctoral Training Centre, University of Oxford.

This material has been adapted from material by Fergus Cooper and others from the "Essential Mathematics" module at the Doctoral Training Centre, University of Oxford.

Creative Commons License
This course material was developed as part of UNIVERSE-HPC, which is funded through the SPF ExCALIBUR programme under grant number EP/W035731/1

This course material was developed as part of UNIVERSE-HPC, which is funded through the SPF ExCALIBUR programme under grant number EP/W035731/1

Creative Commons License

Differentiation 1


YouTube lecture recording from October 2020

A recording of this lecture from October 2020; the material has changed a little since.
Youtube lecture thumbnail

Why differentiation?

We often want to know about the rate at which one quantity changes over time. Examples:
  1. The rate of disappearance of substrate with time in an enzyme reaction.
  2. The rate of decay of a radioactive substance (how long will it have activity above a certain level?)
  3. The rate of bacterial cell growth over time.
  4. How quickly an epidemic is growing.
Differentiation gives us this rate exactly, as a formula. Once we have the rate, we can use it to find where a quantity is greatest or smallest (e.g. the time at which the most bacteria are on a plate), and to sketch its graph.

Gradients

Defining the gradient

  • The gradient of a curve at a point PP is the slope of the tangent of the curve at that point.
  • The tangent is the line that "just touches" the curve.
  • The gradient is also known as the rate of change or derivative, and the process of finding the gradient is called differentiation.
  • The gradient of the curve y=f(x)y = f(x) is denoted in a few different ways, the three most common are:
y′,f′(x),dydx.y', \quad f'(x), \quad \frac{dy}{dx}.

Example, y=x2y = x^2

At x=1x=1 the gradient is shallow and sloping up to the right:
Gradient of x squared
At x=−2x=-2 the gradient is steeper, and sloping down to the right:
Gradient of x squared

Example, y=ln⁡(x)y = \ln(x)

For this function, the gradient is always sloping up to the right, but gets shallower as xx increases:
Gradient of log x

Algebraic example

If we want to find y′(x)y'(x) for y=x3+2y = x^3 + 2:
Gradient=y2−y1x2−x1=ΔyΔx\text{Gradient} = \frac{y_2 - y_1}{x_2-x_1} = \frac{\Delta y}{\Delta x}
Try with
x1=1.5,1.9,1.99,…x2=2.5,2.1,2.01,…\begin{aligned} x_1 &= 1.5,\quad 1.9,\quad 1.99,\quad \ldots \\ x_2 &= 2.5,\quad 2.1,\quad 2.01,\quad \ldots \end{aligned}
We can use Python as a calculator to evaluate these differences, with x1=2−hx_1 = 2 - h and x2=2+hx_2 = 2 + h:
for h in [0.5, 0.1, 0.01]: x_1 = 2 - h x_2 = 2 + h y_1 = x_1**3 + 2 y_2 = x_2**3 + 2 print(h, (y_2 - y_1)/(x_2 - x_1))
0.5 12.25 0.1 12.010000000000003 0.01 12.00009999999997
As the difference between x1x_1 and x2x_2 gets smaller, the gradient stabilises. The value it converges to is the gradient at the midway point of x1x_1 and x2x_2.

Calculating gradients exactly

Gradient≈ΔyΔx=f(x+h)−f(x)h\text{Gradient} \approx \frac{\Delta y}{\Delta x} = \frac{f(x+h) - f(x)}{h}
This is called a finite difference approximation to the gradient. The approximation becomes more accurate the smaller hh is.
When using the approximation, we denote the changes as Δy/Δx\Delta y/\Delta x. In the limit as hh goes to 0, this becomes the derivative, dy/dxdy/dx:
dydx=lim⁡h→0f(x+h)−f(x)h\frac{dy}{dx} = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}
In this way, d/dxd/dx is an operator, acting on yy.
Note, the dds cannot be cancelled out, as they aren't variables, they denote an infinitely small change.
Notice how, as the finite difference gets smaller and smaller, the approximation to the gradient (the green line) gets closer and closer to the true gradient (the orange line):
Finite difference approximation 1
Finite difference approximation 2

Example

Find the gradient of y=f(x)=x3+2y = f(x) = x^3 + 2.
f(x+h)−f(x)h=(x+h)3+2−(x3+2)h=x3+3x2h+3xh2+h3+2−x3−2h=3x2h+3xh2+h3h=3x2+3xh+h2\begin{aligned} \frac{f(x+h) - f(x)}{h} &= \frac{(x+h)^3 + 2 - (x^3 + 2)}{h} \\ &= \frac{x^3 + 3x^2 h + 3xh^2 + h^3 + 2 - x^3 - 2}{h} \\ &= \frac{3x^2h + 3xh^2 + h^3}{h} \\ &= 3x^2 + 3xh + h^2 \end{aligned}
Now this is only exactly right when h→0h \rightarrow 0. So letting that happen, we have
dydx=lim⁡h→0(3x2+3xh+h2)=3x2\frac{dy}{dx} = \lim_{h \to 0} \left(3x^2 + 3xh + h^2\right) = 3x^2

Derivative of polynomial functions

Using techniques like the one above (which is called differentiation from first principles), one can generalise the connection between powers of xx and their derivatives:
If y=axny = a x^n, then its derivative is
dydx=y′(x)=anxn−1\frac{dy}{dx} = y'(x) = a n x^{n-1}

Examples to try

  1. y=x4y = x^4
  2. y=7x5y = 7x^5
  3. y=x−2=1/x2y = x^{-2} = 1/x^2
  4. y=1/x=(1/x)1/2=x−1/2y = \sqrt{1/x} = (1/x)^{1/2} = x^{-1/2}

Summing and multiplying derivatives

Summing

(f(x)±g(x))′=f′(x)±g′(x)(f(x) \pm g(x))' = f'(x) \pm g'(x)
e.g.
y=x2+x3,y′=2x+3x2y = x^2 + x^3, \quad y' = 2x + 3x^2

Multiplying (by a scalar)

(af(x))′=af′(x)(a f(x))' = a f'(x)
e.g.
y=6x3,y′=6⋅3x2=18x2y = 6x^3, \quad y' = 6 \cdot 3x^2 = 18 x^2
This only works for scalars.
In most circumstances (f(x)g(x))′≠f′(x)g′(x)(f(x) g(x))' \neq f'(x) g'(x) (more on this in the next lecture)
e.g.
y=x⋅x=x2,y′≠1y = x\cdot x = x^2, \quad y' \neq 1

Higher-order derivatives

You can take a derivative of a function multiple times in a row. This is usually denoted either y′′(x)y''(x), f′′(x)f''(x) or d2y/dx2d^2 y/dx^2 for second-order derivatives (differentiating twice), and similar for higher orders.
e.g.
y=x3y′=3x2y′′=d2ydx2=6x\begin{aligned} y &= x^3 \\ y' &= 3x^2 \\ y'' &= \frac{d^2 y}{dx^2} = 6 x \end{aligned}

Interpreting derivatives

The sign of the first derivative f′(x)f'(x) tells us how f(x)f(x) is growing
  • Positive gradient: If y′>0y' > 0 then yy is increasing at xx
  • Negative gradient: If y′<0y' < 0 then yy is decreasing at xx
  • Zero gradient: If y′=0y' = 0 then yy is not changing (flat) at xx

Stationary points and points of inflection

Stationary points are where dy/dx=0dy/dx = 0.
  1. Local maximum: dy/dx=0dy/dx = 0 and d2y/dx2<0d^2y/dx^2 < 0
  2. Local minimum: dy/dx=0dy/dx = 0 and d2y/dx2>0d^2y/dx^2 > 0
  3. Inflection: d2y/dx2=0d^2y/dx^2 = 0 and d2y/dx2d^2y/dx^2 changes sign
If dy/dx=0dy/dx = 0 and d2y/dx2=0d^2y/dx^2 = 0, this test does not tell us which it is (e.g. y=x3y = x^3 and y=x4y = x^4 at x=0x = 0), so look at the sign of dy/dxdy/dx on either side.

Example: find the stationary points of y=2x3−5x2−4xy = 2x^3 - 5x^2 - 4x

To do this, we need to know both y′(x)y'(x) and y′′(x)y''(x).
y′(x)=6x2−10x−4y′′(x)=12x−10\begin{aligned} y'(x) &= 6x^2 - 10x - 4 \\ y''(x) &= 12x - 10 \end{aligned}
Stationary points occur when y′(x)=0y'(x) = 0
6x2−10x−4=0(3x+1)(2x−4)=0x=−1/3,2\begin{aligned} 6x^2 - 10x - 4 &= 0 \\ (3x + 1)(2x - 4) &= 0 \\ x &= -1/3,\quad 2 \end{aligned}
At x=−1/3x = -1/3:
y′′(−1/3)=12×−1/3−10=−14<0y''(-1/3) = 12 \times -1/3 - 10 = -14 < 0
So this point is a maximum.
At x=2x = 2
y′′(2)=12×2−10=14>0y''(2) = 12 \times 2 - 10 = 14 > 0
So this point is a minimum.
Inflection points can only occur where y′′(x)=0y''(x) = 0
y′′(x)=12x−10=0x=1012=56\begin{aligned} y''(x) &= 12x - 10 = 0 \\ x &= \frac{10}{12} = \frac{5}{6} \end{aligned}
Since y′′(x)y''(x) changes sign at x=5/6x = 5/6, this is an inflection point.
Note: Points of inflection do not require that y′(x)=0y'(x) = 0, only that y′′(x)=0y''(x) = 0 and changes sign.
Points of inflection are important in biology as they define conditions where a response (e.g. reaction rate) is most or least sensitive to a change in conditions (e.g. the concentration of a metabolite).

Sketching: the checklist revisited

To sketch the graph of a function (as in the lecture on graphs):
  • Find where it is zero, positive and negative
  • Look at which terms dominate as x→±∞x\to\pm\infty
  • Look at the limit behaviour as xx approaches any points where the function is undefined (e.g. x→0x\to 0 for y=1/xy=1/x), which may give an asymptote
  • Find the turning points and points of inflection, using the first and second derivatives
Then check your sketch by plotting the function in Python.

Example: sketching y=2x3−5x2−4xy = 2x^3 - 5x^2 - 4x

  • It factorises as y=x(2x2−5x−4)y = x(2x^2 - 5x - 4), so y=0y = 0 at x=0x = 0 and x=(5±57)/4x = (5 \pm \sqrt{57})/4, i.e. x≈−0.64x \approx -0.64 and x≈3.14x \approx 3.14
  • For large ∣x∣|x|, the 2x32x^3 term dominates, so yy rises to the right and falls to the left
  • It is defined for all xx, so there are no asymptotes
  • From the example above, it has a maximum at x=−1/3x = -1/3, a minimum at x=2x = 2 and a point of inflection at x=5/6x = 5/6
Turning points

Example: bacteria on a plate

The number nn (in thousands) of bacteria on an agar plate at time tt (in days) is given by the expression:
n=15.42+6t−t2n = 15.42 + 6t - t^2
  1. Find the time at which the greatest number of bacteria are present on the plate.
  2. Find the number of bacteria on the plate at this time.

Solution

To do this we must find the turning points of the function.
  1. Find the time at which the greatest number of bacteria are present on the plate
    n(t)=15.42+6t−t2n′(t)=6−2tn′(t)=0  ⟹  6−2t=0  ⟹  t=3\begin{aligned} n(t) &= 15.42 + 6t - t^2 \\ n'(t) &= 6 - 2t \\ n'(t) &= 0 \quad\implies\quad 6-2t=0\quad\implies\quad t=3 \end{aligned}
    To show this is a maximum, we need to check n′′(t)n''(t)
    n′′(t)=−2n''(t) = -2
    Therefore, n′′(t)<0n''(t)<0, for t=3t = 3. This means that a maximum occurs at t=3t = 3 days.
  2. Find the number of bacteria on the plate at this time
    n(3)=15.42+6×3−32=24.42n(3) = 15.42 + 6 \times 3 - 3^2 = 24.42
    The greatest number of bacteria on the plate is 24,420.

Example: logistic growth

The growth rate RR of a cell colony with NN cells at time tt can be represented by the equation
R=dNdt=kN−bN2R = \frac{d N}{d t} = kN - bN^2
For this example take the constants kk and bb as k=3.8k = 3.8/hr, and b=0.01b = 0.01/cell/hr. This is called a logistic model.
  1. What is the equilibrium size of the population?
  2. What population size leads to the largest growth rate?

Solution

  1. The equilibrium will occur when the population stops changing, i.e. when R=0R = 0. Meaning:
    R=3.8N−0.01N2=0N(3.8−0.01N)=0\begin{aligned} R = 3.8 N - 0.01 N^2 &= 0 \\ N (3.8 - 0.01 N) &= 0 \end{aligned}
    We can disregard the N=0N = 0 solution, as it represents population extinction. This means that
    N=3.80.01=380.N = \frac{3.8}{0.01} = 380.
  2. To find the largest growth rate, we want the maximal value of R(N)R(N). This means we need to find R′(N)=0R'(N) = 0.
    R(N)=3.8N−0.01N2R′(N)=3.8−0.02N\begin{aligned} R(N) &= 3.8 N - 0.01 N^2 \\ R'(N) &= 3.8 - 0.02 N \end{aligned}
    If R′(N)=0R'(N) = 0
    3.8−0.02N=0N=190\begin{aligned} 3.8 - 0.02N &= 0 \\ N &= 190 \end{aligned}
    Since R′′(N)=−0.02<0R''(N) = -0.02 < 0, we can be sure that this is a maximum.

Introductory problems

Tip

For more practice, an AI tool can write new problems like the ones below. Ask it for problems of the same type and difficulty, or for problems set in your own field. For example, you could ask it to "write five pharmacology problems on maxima and minima, at the level of these ones". Work them on paper first, then ask the tool to check your answers and to explain any step you are unsure of.

Introductory problems 1

Use the formula
dydx=lim⁡h→0(f(x+h)−f(x)h)\frac{dy}{dx}=\lim_{h\rightarrow 0}\left(\frac{f(x+h)-f(x)}{h}\right)
to calculate the derivatives of the functions below. Check your answers by using the standard rules for differentiation:
  1. y=3x+3y = 3x + 3
  2. y=4x2−3x+2y = 4x^2 - 3x + 2
  3. y=2x3−5y = 2x^3-5
  4. y=1/x2y=1/x^2\qquad (harder)

Introductory problems 2

Find the gradient at the given points of the following curves:
  1. y=x3−4wherex=1y = x^3 - 4 \qquad\text{where}\qquad x = 1
  2. y=3x3+4x−3wherex=−2y = 3x^3 + 4x - 3 \qquad\text{where}\qquad x = -2

Introductory problems 3

Find the xx and yy coordinates of the points on the given curves at which the gradient is zero (if any) and find out whether they are maxima, minima or points of inflexion:
  1. y=(x−3)(x−4)y = (x - 3)(x - 4)
  2. y=x3−4x2+2x−2y = x^3 - 4x^2 + 2x - 2
  3. y=(4x+1)/xy = (4x+1)/x
  4. y=16−2x3y = 16 - 2x^3

Main problems

Main problems 1

One hour after taking x mgx\,\text{mg} of a drug, the body temperature, TT, in ∘^\circC of a patient is given by:
T=T0−0.000625 x2(18−x),T=T_0-0.000625\,x^2(18-x),
where T0T_0 is the initial body temperature.
  1. Determine the value of xx that produces the greatest drop in body temperature, and the magnitude of that temperature change.
  2. Sketch TT as a function of the dose.

Main problems 2

The formula for the Lennard Jones potential between two non polar atoms is given in terms of the positive constants AA and BB and the internuclear distance, RR, as:
V(R)=AR12−BR6V(R)=\frac{A}{R^{12}} - \frac{B}{R^6}
  1. Use this formula to calculate dV/dRdV/dR as a function of RR.
  2. Show that the potential where the gradient is zero is V(R)=−B2/(4A)V(R)=-B^2/(4A).
  3. Find mathematically whether this point is a maximum, minimum or point of inflexion.

Main problems 3

The number nn (in thousands) of bacteria on an agar plate at time tt days is given by the expression:
n=21.35+1.34t−t2n = 21.35 + 1.34t - t^2
  1. Draw a graph of the function n(t)n(t) between t=0t=0 and t=7t=7 days. Give one reason why this function might be a reasonable model for the number of bacteria on the plate at time tt. Are there any values of tt for which this is probably not a good model?
  2. Calculate the time at which the greatest number of bacteria are present on the plate and show that this must be a maximum number.
  3. By finding the roots of the equation for nn, find the two times at which the value of nn is zero and say why only one of these times is physically reasonable. Mark and label the maximum point on your graph together with the point at which the number of bacteria is zero.
  4. Find the rates at which the bacteria are growing when t=0.8t=0.8 and t=3.5t=3.5 days.

Main problems 4

Being able to change direction rapidly helps fish to avoid predators. We can describe the distance xx (in cm) travelled by time tt seconds after a stimulus by
x=ktb,x = kt^b,
where for rainbow trout k=300 cm s−1.6k=300\,\text{cm}\,\text{s}^{-1.6}, b=1.60b=1.60, and for green sunfish k=210 cm s−1.71k=210\,\text{cm}\,\text{s}^{-1.71}, b=1.71b=1.71.
  1. Compare the distance travelled, and the instantaneous velocity and acceleration for these species at t=0.1 t=0.1\,s.
  2. Compare the velocities in fish lengths per second, given that the lengths of trout and sunfish are 14.4 14.4\,cm and 8.0 8.0\,cm respectively, commenting on your answer.

Main problems 5

A researcher measured the concentration cc of a protein in vitro and obtained the readings below:
time (min)0123456
c (mM)11.917.064.402.571.811.030.72
She suspected that the protein is degraded at a rate proportional to its concentration, so that
c=c0e−ktc = c_0 e^{-kt}
where c0c_0 and kk are positive constants.
  1. Use a suitable transformation to draw a straight-line graph of the data, in order to test her hypothesis.
  2. Find the maximum rate of decay and the time at which this occurs.
  3. Find the concentration of protein remaining after 10 minutes.

Extension problems

Extension problems 1

Find the values of xx for which the following functions have stationary values and using your results, sketch a graph of each function. You will need the fact that the derivative of exe^x is exe^x (more on this in the next lecture).
  1. y=2ex−xy = 2e^x - x
  2. y=ex−2x−1y = e^x - 2x - 1
Use Python to check your results.

Extension problems 2

The graph shows the rate of CO2_2 emissions per year since 1850, with three fitted lines in red.
CO2 graph
A climate scientist thinks that a quadratic curve could be a better fit to the data, with the x-axis as years since 1850, and the y-axis as the rate of CO2_2 emissions per year. The curve would have the equation
y=Ax2+Bx+Cy = Ax^{2} + Bx + C
  1. By using the points (10,3),(106,14),(166,42)(10,3), (106,14), (166,42) taken from the best fit lines, evaluate the coefficients AA, BB, and CC in this model.
  2. Find the minimum of this quadratic curve. Use this to assess the suitability of the quadratic model as a fit for the data.

Extension problems 3

A protein degrades according to the formula
p(t)=12kt+1P0p(t) = \frac{1}{2kt + \frac{1}{P_0}}
where pp is the protein concentration, P0P_0 is the initial concentration, kk is a constant, and tt is time.
Show that dp/dt=−2kp2dp/dt = -2kp^2. How does this differ from a protein that is degraded at a rate proportional to pp?

Extension problems 4

From first principles (as in the first question on this sheet) prove the formulas for differentiation of sums, differences and scalar multiples.