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 course material was developed as part of UNIVERSE-HPC, which is funded through the SPF ExCALIBUR programme under grant number EP/W035731/1
Differentiation 1
Learning outcomes
Understand the concept of the rate of change of a quantity
Be able to calculate the gradient of a curve at a point
Understand the relationship between the derivative and gradient of a function
Be able to calculate and interpret the derivative of a function
YouTube lecture recording from October 2020
A recording of this lecture from October 2020; the material has changed a little since.
Why differentiation?
We often want to know about the rate at which one quantity changes over time.
Examples:
The rate of disappearance of substrate with time in an enzyme reaction.
The rate of decay of a radioactive substance (how long will it have activity above a certain level?)
The rate of bacterial cell growth over time.
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 P 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) is denoted in a few different ways, the three most common are:
y′,f′(x),dxdy.
Example, y=x2
At x=1 the gradient is shallow and sloping up to the right:
At x=−2 the gradient is steeper, and sloping down to the right:
Example, y=ln(x)
For this function, the gradient is always sloping up to the right, but gets shallower as x increases:
Algebraic example
If we want to find y′(x) for y=x3+2:
Gradient=x2−x1y2−y1=ΔxΔy
Try with
x1x2=1.5,1.9,1.99,…=2.5,2.1,2.01,…
We can use Python as a calculator to evaluate these differences, with x1=2−h and x2=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+2print(h,(y_2 - y_1)/(x_2 - x_1))
As the difference between x1 and x2 gets smaller, the gradient stabilises.
The value it converges to is the gradient at the midway point of x1 and x2.
Calculating gradients exactly
Gradient≈ΔxΔy=hf(x+h)−f(x)
This is called a finite difference approximation to the gradient. The approximation becomes more accurate the smaller h is.
When using the approximation, we denote the changes as Δy/Δx. In the limit as h goes to 0, this becomes the derivative, dy/dx:
dxdy=h→0limhf(x+h)−f(x)
In this way, d/dx is an operator, acting on y.
Note, the ds 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):
Now this is only exactly right when h→0. So letting that happen, we have
dxdy=h→0lim(3x2+3xh+h2)=3x2
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 x and their derivatives:
If y=axn, then its derivative is
dxdy=y′(x)=anxn−1
Examples to try
y=x4
y=7x5
y=x−2=1/x2
y=1/x=(1/x)1/2=x−1/2
Summing and multiplying derivatives
Summing
(f(x)±g(x))′=f′(x)±g′(x)
e.g.
y=x2+x3,y′=2x+3x2
Multiplying (by a scalar)
(af(x))′=af′(x)
e.g.
y=6x3,y′=6⋅3x2=18x2
This only works for scalars.
In most circumstances (f(x)g(x))′=f′(x)g′(x) (more on this in the next lecture)
e.g.
y=x⋅x=x2,y′=1
Higher-order derivatives
You can take a derivative of a function multiple times in a row. This is usually denoted either y′′(x), f′′(x) or d2y/dx2 for second-order derivatives (differentiating twice), and similar for higher orders.
e.g.
yy′y′′=x3=3x2=dx2d2y=6x
Interpreting derivatives
The sign of the first derivative f′(x) tells us how f(x) is growing
Positive gradient: If y′>0 then y is increasing at x
Negative gradient: If y′<0 then y is decreasing at x
Zero gradient: If y′=0 then y is not changing (flat) at x
Stationary points and points of inflection
Stationary points are where dy/dx=0.
Local maximum: dy/dx=0 and d2y/dx2<0
Local minimum: dy/dx=0 and d2y/dx2>0
Inflection: d2y/dx2=0 and d2y/dx2 changes sign
If dy/dx=0 and d2y/dx2=0, this test does not tell us which it is (e.g. y=x3 and y=x4 at x=0), so look at the sign of dy/dx on either side.
Example: find the stationary points of y=2x3−5x2−4x
To do this, we need to know both y′(x) and y′′(x).
y′(x)y′′(x)=6x2−10x−4=12x−10
Stationary points occur when y′(x)=0
6x2−10x−4(3x+1)(2x−4)x=0=0=−1/3,2
At x=−1/3:
y′′(−1/3)=12×−1/3−10=−14<0
So this point is a maximum.
At x=2
y′′(2)=12×2−10=14>0
So this point is a minimum.
Inflection points can only occur where y′′(x)=0
y′′(x)x=12x−10=0=1210=65
Since y′′(x) changes sign at x=5/6, this is an inflection point.
Note: Points of inflection do not require that y′(x)=0, only that y′′(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→±∞
Look at the limit behaviour as x approaches any points where the function is undefined (e.g. x→0 for y=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−4x
It factorises as y=x(2x2−5x−4), so y=0 at x=0 and x=(5±57)/4, i.e. x≈−0.64 and x≈3.14
For large ∣x∣, the 2x3 term dominates, so y rises to the right and falls to the left
It is defined for all x, so there are no asymptotes
From the example above, it has a maximum at x=−1/3, a minimum at x=2 and a point of inflection at x=5/6
Example: bacteria on a plate
The number n (in thousands) of bacteria on an agar plate at time t (in days) is given by the expression:
n=15.42+6t−t2
Find the time at which the greatest number of bacteria are present on the plate.
Find the number of bacteria on the plate at this time.
Solution
To do this we must find the turning points of the function.
Find the time at which the greatest number of bacteria are present on the plate
n(t)n′(t)n′(t)=15.42+6t−t2=6−2t=0⟹6−2t=0⟹t=3
To show this is a maximum, we need to check n′′(t)
n′′(t)=−2
Therefore, n′′(t)<0, for t=3. This means that a maximum occurs at t=3 days.
Find the number of bacteria on the plate at this time
n(3)=15.42+6×3−32=24.42
The greatest number of bacteria on the plate is 24,420.
Example: logistic growth
The growth rate R of a cell colony with N cells at time t can be represented by the equation
R=dtdN=kN−bN2
For this example take the constants k and b as k=3.8/hr, and b=0.01/cell/hr. This is called a logistic model.
What is the equilibrium size of the population?
What population size leads to the largest growth rate?
Solution
The equilibrium will occur when the population stops changing, i.e. when R=0. Meaning:
R=3.8N−0.01N2N(3.8−0.01N)=0=0
We can disregard the N=0 solution, as it represents population extinction. This means that
N=0.013.8=380.
To find the largest growth rate, we want the maximal value of R(N). This means we need to find R′(N)=0.
R(N)R′(N)=3.8N−0.01N2=3.8−0.02N
If R′(N)=0
3.8−0.02NN=0=190
Since R′′(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
dxdy=h→0lim(hf(x+h)−f(x))
to calculate the derivatives of the functions below.
Check your answers by using the standard rules for differentiation:
y=3x+3
y=4x2−3x+2
y=2x3−5
y=1/x2 (harder)
hf(x+h)−f(x)=h3(x+h)+3−(3x+3)=h3h=3
This does not depend on h, so dy/dx=3.
Check: the derivative of 3x is 3 and the derivative of a constant is 0.
Find the gradient at the given points of the following curves:
y=x3−4wherex=1
y=3x3+4x−3wherex=−2
dy/dx=3x2, so at x=1 the gradient is 3.
dy/dx=9x2+4, so at x=−2 the gradient is 9×4+4=40.
Introductory problems 3
Find the x and y 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:
y=(x−3)(x−4)
y=x3−4x2+2x−2
y=(4x+1)/x
y=16−2x3
Expand first: y=x2−7x+12, so dy/dx=2x−7, which is zero at x=7/2.
Then y=(7/2−3)(7/2−4)=−1/4.
Since d2y/dx2=2>0, the point (7/2,−1/4) is a minimum.
dy/dx=3x2−8x+2, which is zero when
x=68±64−24=34±10
so x≈0.279 or x≈2.387.
Substituting back gives y=(−110+2010)/27≈−1.73 and y=(−110−2010)/27≈−6.42 respectively.
Next, d2y/dx2=6x−8, which is −210<0 at x=(4−10)/3 and 210>0 at x=(4+10)/3.
So (0.279,−1.73) is a maximum and (2.387,−6.42) is a minimum.
Write y=4+1/x=4+x−1, so dy/dx=−1/x2.
This is never zero, so the curve has no points with zero gradient.
dy/dx=−6x2, which is zero only at x=0, where y=16.
Here d2y/dx2=−12x=0, so the second derivative does not tell us the type.
Look at the gradient either side instead: −6x2<0 for every x=0, so the curve is decreasing on both sides.
This means that (0,16) is a point of inflexion.
Main problems
Main problems 1
One hour after taking xmg of a drug, the body temperature, T, in ∘C of a patient is given by:
T=T0−0.000625x2(18−x),
where T0 is the initial body temperature.
Determine the value of x that produces the greatest drop in body temperature, and the magnitude of that temperature change.
Sketch T as a function of the dose.
Expand first: T=T0−0.01125x2+0.000625x3.
Then
dxdT=−0.0225x+0.001875x2=0.001875x(x−12)
which is zero at x=0 and x=12.
Next, d2T/dx2=−0.0225+0.00375x, which is 0.0225>0 at x=12, so T has a minimum there.
So, the greatest drop in temperature comes from a dose of 12mg, and the drop is
T0−T=0.000625×122×(18−12)=0.54∘C
T starts at T0 when x=0 (a maximum, since d2T/dx2=−0.0225<0 there).
It falls to its minimum, T0−0.54, at x=12, then rises back to T0 at x=18.
For x>18 the formula gives T>T0, so we should only use the model for doses between 0 and 18mg.
import numpy as np
from matplotlib import pyplot as plt
x = np.linspace(0,18,100)drop =0.000625* x**2*(18- x)plt.plot(x,-drop)plt.xlabel('dose, x (mg)')plt.ylabel('change in temperature, T - T0 (C)')
Main problems 2
The formula for the Lennard Jones potential between two non polar atoms is given in terms of the positive constants A and B and the internuclear distance, R, as:
V(R)=R12A−R6B
Use this formula to calculate dV/dR as a function of R.
Show that the potential where the gradient is zero is V(R)=−B2/(4A).
Find mathematically whether this point is a maximum, minimum or point of inflexion.
Write V=AR−12−BR−6, so
dRdV=−12AR−13+6BR−7=−R1312A+R76B
Setting dV/dR=0 and multiplying through by R13 gives 6BR6=12A, so R6=2A/B.
Substituting this into V, with R12=(R6)2=4A2/B2:
V=4A2/B2A−2A/BB=4AB2−2AB2=−4AB2
Differentiate again:
dR2d2V=R14156A−R842B=R81(R6156A−42B)
At the stationary point R6=2A/B, so 156A/R6=78B and
dR2d2V=R878B−42B=R836B>0
since B is positive.
Therefore, this point is a minimum.
This is the separation at which the two atoms are most stable.
Main problems 3
The number n (in thousands) of bacteria on an agar plate at time t days is given by the expression:
n=21.35+1.34t−t2
Draw a graph of the function n(t) between t=0 and t=7 days. Give one reason why this function might be a reasonable model for the number of bacteria on the plate at time t. Are there any values of t for which this is probably not a good model?
Calculate the time at which the greatest number of bacteria are present on the plate and show that this must be a maximum number.
By finding the roots of the equation for n, find the two times at which the value of n 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.
Find the rates at which the bacteria are growing when t=0.8 and t=3.5 days.
Some values to plot:
t (days)
0
1
2
3
4
5
6
7
n (thousands)
21.35
21.69
20.03
16.37
10.71
3.05
-6.61
-18.27
The graph is an upside-down parabola.
It might be a reasonable model because the number rises a little at first, then falls as the bacteria run out of food and die (any sensible reason is fine).
It is not a good model after about 5.3 days, where it gives a negative number of bacteria.
import numpy as np
from matplotlib import pyplot as plt
t = np.linspace(0,7,100)n =21.35+1.34* t - t**2plt.plot(t, n)plt.axhline(0, color='k')plt.xlabel('t (days)')plt.ylabel('n (thousands)')
dn/dt=1.34−2t, which is zero at t=0.67 days.
Since d2n/dt2=−2<0, this is a maximum.
The number of bacteria at this time is n=21.35+1.34×0.67−0.672≈21.8 thousand.
Solve −t2+1.34t+21.35=0 with the quadratic formula:
t=−2−1.34±1.342+4×21.35=−2−1.34±9.34
so t≈5.34 or t≈−4.00 days.
Only t≈5.34 days is physically reasonable, since the plate was only set up at t=0.
Mark (0.67,21.8) and (5.34,0) on the graph.
dn/dt=1.34−2t, so at t=0.8 the rate is 1.34−1.6=−0.26 thousand bacteria per day, and at t=3.5 it is 1.34−7=−5.66 thousand bacteria per day.
Both are negative, so the number of bacteria is falling at these times, and much faster at t=3.5.
Main problems 4
Being able to change direction rapidly helps fish to avoid predators. We can describe the distance x (in cm) travelled by time t seconds after a stimulus by
x=ktb,
where for rainbow trout k=300cms−1.6, b=1.60, and for green sunfish k=210cms−1.71, b=1.71.
Compare the distance travelled, and the instantaneous velocity and acceleration for these species at t=0.1s.
Compare the velocities in fish lengths per second, given that the lengths of trout and sunfish are 14.4cm and 8.0cm respectively, commenting on your answer.
Differentiating x=ktb once and twice gives the velocity and acceleration:
v=dtdx=kbtb−1,a=dt2d2x=kb(b−1)tb−2
At t=0.1s:
trout
sunfish
distance, x (cm)
7.54
4.09
velocity, v (cm s−1)
121
70
acceleration, a (cm s−2)
723
497
So, at this time the trout has gone further, and is moving and accelerating faster, than the sunfish.
Dividing by body length, the trout moves at 120.6/14.4≈8.4 lengths per second and the sunfish at 70.0/8.0≈8.8 lengths per second.
In other words, for its size the smaller sunfish is slightly faster.
This may be a fairer comparison, since a larger fish needs to travel further to get clear of a predator.
Main problems 5
A researcher measured the concentration c of a protein in vitro and obtained the readings below:
time (min)
0
1
2
3
4
5
6
c (mM)
11.91
7.06
4.40
2.57
1.81
1.03
0.72
She suspected that the protein is degraded at a rate proportional to its concentration, so that
c=c0e−kt
where c0 and k are positive constants.
Use a suitable transformation to draw a straight-line graph of the data, in order to test her hypothesis.
Find the maximum rate of decay and the time at which this occurs.
Find the concentration of protein remaining after 10 minutes.
Take the natural log of both sides:
lnc=lnc0+lne−kt=lnc0−kt
This is the equation of a straight line, with Y=lnc, X=t, gradient −k and intercept lnc0.
So we plot lnc against t.
The points lie close to a straight line, so the data are consistent with her hypothesis.
As in lecture 2, we fit the best straight line through the points:
import numpy as np
t = np.array([0,1,2,3,4,5,6])c = np.array([11.91,7.06,4.40,2.57,1.81,1.03,0.72])# Fit the best straight line through the pointsgradient, intercept = np.polyfit(t, np.log(c),1)print('gradient =', gradient)print('intercept =', intercept)
The protein is degraded at a rate proportional to its concentration, kc.
This is largest when c is largest, which is at the start, t=0.
The maximum rate of decay is kc0≈0.47×11.4≈5.3mM per minute.
c(10)≈11.4e−0.47×10≈0.10mM.
Extension problems
Extension problems 1
Find the values of x 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 ex is ex (more on this in the next lecture).
y=2ex−x
y=ex−2x−1
Use Python to check your results.
dy/dx=2ex−1, which is zero when ex=1/2, so x=ln(1/2)=−ln2≈−0.69.
There, y=2×21+ln2=1+ln2≈1.69.
Since d2y/dx2=2ex>0 for every x, this is a minimum.
The curve crosses the y axis at (0,2).
For large negative x, ex→0, so the curve approaches the line y=−x, and for large positive x it grows like 2ex.
dy/dx=ex−2, which is zero when ex=2, so x=ln2≈0.69.
There, y=2−2ln2−1=1−2ln2≈−0.39.
Since d2y/dx2=ex>0, this is a minimum.
The curve passes through the origin, since y=1−0−1=0 at x=0.
For large negative x the curve approaches the line y=−2x−1.
import numpy as np
from matplotlib import pyplot as plt
x = np.linspace(-3,2,100)plt.plot(x,2* np.exp(x)- x, label='y = 2e^x - x')plt.plot(x, np.exp(x)-2* x -1, label='y = e^x - 2x - 1')plt.axhline(0, color='k')plt.xlabel('x')plt.ylabel('y')plt.legend()
Extension problems 2
The graph shows the rate of CO2 emissions per year since 1850, with three fitted lines in red.
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 emissions per year. The curve would have the equation
y=Ax2+Bx+C
By using the points (10,3),(106,14),(166,42) taken from the best fit lines, evaluate the coefficients A, B, and C in this model.
Find the minimum of this quadratic curve. Use this to assess the suitability of the quadratic model as a fit for the data.
Each point gives one equation:
100A+10B+C11236A+106B+C27556A+166B+C=3=14=42
Subtracting the first equation from the second, and the second from the third, removes C:
11136A+96B16320A+60B=11=28
Multiplying the first of these by 5 and the second by 8 gives 55680A+480B=55 and 130560A+480B=224.
Subtracting, 74880A=169, so A=13/5760≈0.00226.
Substituting back gives B=−53/360≈−0.147 and C=1223/288≈4.25.
dy/dx=2Ax+B, which is zero at
x=−2AB=13/288053/360=13424≈32.6
Since d2y/dx2=2A>0, this is a minimum, with y≈1.85.
So, the model has a minimum in about 1883, and says that emissions fell from about 4.2 billion tonnes per year in 1850 to 1.85 in 1883.
The data show emissions rising steadily over this time, so the quadratic model is not a good fit for the early data.
Extension problems 3
A protein degrades according to the formula
p(t)=2kt+P011
where p is the protein concentration, P0 is the initial concentration, k is a constant, and t is time.
Show that dp/dt=−2kp2.
How does this differ from a protein that is degraded at a rate proportional to p?
Write p=(2kt+1/P0)−1 and use the rule for differentiating a power, treating the bracket as one quantity (this is the chain rule, which we cover in the next lecture):
dtdp=−(2kt+P01)−2×2k=−2k(2kt+1/P01)2=−2kp2
So, the protein is degraded at a rate proportional to the square of its concentration.
If the rate were proportional to p, doubling the concentration would double the rate of degradation.
Here, doubling the concentration makes it four times as fast.
This means that the protein is degraded quickly when there is a lot of it, but very slowly once there is little left.
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.
Let f and g be functions of x, and a a constant.
For a sum, regroup the terms of the difference quotient: