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 2
Learning outcomes
Be able to recognise the derivatives of standard functions
Be able to differentiate sums and scalar multiples of functions
Be able to use the chain rule to differentiate a function of a function
Be able to use the product rule for differentiating a product of functions
Be able to use the quotient rule for differentiating the ratio of functions
Be able to differentiate inverse functions
Be able to use the derivative to make a linear approximation
Be able to use SymPy to calculate derivatives in Python
YouTube lecture recording from October 2020
A recording of this lecture from October 2020; the material has changed a little since.
Why these rules?
In the last lecture we found the derivative of axn.
Most functions we meet are built from simpler ones, by multiplying them, dividing them, or putting one inside another (e.g. 1+x2).
In this lecture we find a rule for each of these, so that we can differentiate any function built from the standard ones.
We also use the derivative to approximate a function close to a point we know.
Standard derivatives
It's useful to know the derivatives of all the standard functions, and some basic rules.
For sin and cos, x must be in radians. We show the derivative of lnx later in this lecture.
To understand the derivative of sin and cos, consider their graphs, and when they are changing positively (increasing), negatively (decreasing) or not at all (no rate of change).
Differentiation of sums and scalar multiples
(f(x)±g(x))′(af(x))′=f′(x)±g′(x)=af′(x)
Differentiation of products
While differentiating sums, and scalar multiples is straightforward, differentiating products is more complex
So both rules produce the same result. While for simple examples the product rule requires more work, as functions get more complex it saves a lot of time.
Differentiating a function of a function: the chain rule
One of the most useful rules is differentiating a function that has another function inside it y=f(g(x)). For this we use the chain rule:
yy′(x)=f(g(x))=f′(g(x))g′(x)=dgdfdxdg
Example 1: y=(5x2+2)4
We can write this as y=g4, where g=5x2+2. Given this, we have that
dgdydxdg=4g3=4(5x2+2)3=10x
This means that
dxdy=dgdydxdg=4(5x2+2)310x=40x(5x2+2)3
This extends to any number of nested functions, meaning
dxda(b(c(x)))=dbdadxdb(c(x))=dbdadcdbdxdc
Differentiating the ratio of two functions: the quotient rule
If y(x)=f(x)/g(x), then by using the product and chain rules on f(x)(g(x))−1, we can show that
In Python, there is a special package for calculating derivatives symbolically, called SymPy.
This can quickly and easily calculate derivatives (as well as do all sorts of other analytic calculations).
import sympy as sp
x = sp.symbols('x')# This creates a variable x, which is symbolically represented as the string x.# Calculate the derivative of x^2sp.diff(x**2, x)
2x
sp.diff(sp.cos(x), x)
−sin(x)
f =(x+1)**3* sp.cos(x**2-5)sp.diff(f,x)
−2x(x+1)3sin(x2−5)+3(x+1)2cos(x2−5)
f =(x+1)**3*(x-2)**2*(x**2+4*x +1)**4sp.diff(f, x)
You can look at the documentation for SymPy to see many other possibilities (e.g. we will use SymPy to do symbolic integration later on in this course)
Try out SymPy to verify your pen & paper answers to the problem sheets.
Introductory problems
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 neuroscience problems on the chain rule, 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
Differentiate the following functions, using the stated rules where indicated:
Differentiate the following trigonometric functions with respect to x:
3sin(x)+5cos(x)
cos(3−2x)
sin(x)
cos(x)/(4x)
3cos(x)−5sin(x)
With u=3−2x, the chain rule gives
dxdcos(3−2x)=−sin(3−2x)×(−2)=2sin(3−2x)
With u=sin(x), y=u1/2:
dxdy=21(sinx)−1/2cosx=2sinxcosx
Using the quotient rule with u=cosx and v=4x:
dxdy=(4x)24x(−sinx)−4cosx=−4x2xsinx+cosx
Introductory problems 3
Use SymPy to check your answers to Introductory problems 1.
SymPy may write a derivative in a different form from yours.
How can you check that the two forms are equal?
For example, for 8.:
import sympy as sp
x = sp.symbols('x')y =(3*x +1)* sp.sqrt(5*x**2- x)print(sp.diff(y, x))
This looks different from our answer.
To check that they are equal, subtract one from the other and simplify:
mine =(60*x**2+ x -1)/(2*sp.sqrt(5*x**2- x))print(sp.simplify(sp.diff(y, x)- mine))
0
The difference is zero, so the two forms are equal.
The other parts can be checked in the same way.
Main problems
Main problems 1
Let y=x2.
Find the exact value of y when x=2.1.
Now estimate the value of y when x=2.1 by using the linear approximation formula
f(x1+h)≈f(x1)+hf′(x1)
and letting x1=2.0 and h=0.1.
Compare your estimate to the true value. Which is bigger? What is there about the shape of the graph of y=x2 that accounts for this?
Repeat parts 1. and 2. for x=2.01.
Calculate the absolute error in each estimate. How does this error change with the value of h?
y=2.12=4.41
Here f(x)=x2 and f′(x)=2x, so
f(2.1)≈f(2.0)+0.1×f′(2.0)=4+0.1×4=4.4
The true value, 4.41, is bigger than the estimate.
The graph of y=x2 curves upwards (its gradient increases), so it lies above its tangent line, and the linear approximation follows the tangent.
The exact value is 2.012=4.0401, and the estimate is 4+0.01×4=4.04.
The errors are 4.41−4.4=0.01 for h=0.1, and 4.0401−4.04=0.0001 for h=0.01.
Dividing h by 10 divides the error by 100, so the error is proportional to h2.
In fact, (2+h)2=4+4h+h2, so the error is exactly h2.
Main problems 2
The energy, E, carried by a photon of wavelength λ is given by
E=λhc
where h is Planck's constant (h=6.63×10−34Js) and c is the speed of light (c=3×108ms−1).
Calculate the energy carried by a photon of wavelength 500nm.
Sketch a graph to show how E varies with λ.
Derive an expression for dE/dλ, and calculate the slope of your graph when λ=500nm.
Hence, or otherwise, estimate the difference in energy between a photon of wavelength 500nm and one of wavelength 505nm.
First convert the wavelength to metres: 500nm=500×10−9m.
Then
E=500×10−96.63×10−34×3×108≈3.98×10−19J
E is inversely proportional to λ, so the graph has the shape of y=1/x for positive x.
E is large for small wavelengths, and decreases towards zero as λ increases, without ever reaching it.
import numpy as np
from matplotlib import pyplot as plt
h =6.63e-34c =3e8wavelength = np.linspace(100e-9,1000e-9,100)plt.plot(wavelength *1e9, h * c / wavelength)plt.xlabel('wavelength (nm)')plt.ylabel('E (J)')
Using the linear approximation, with a change in wavelength of Δλ=5×10−9m:
ΔE≈ΔλdλdE=5×10−9×(−7.96×10−13)≈−3.98×10−21J
So, the photon of wavelength 505nm carries about 4×10−21J less energy, about 1% less.
Main problems 3
On February 10, 1990, the water level in Boston harbour was given by:
y=5+4.9cos(6πt)
where t is the number of hours since midnight and y is measured in feet.
Sketch y.
Find dy/dt. What does it represent, in terms of water level?
For 0≤t≤24, when is dy/dt zero? Explain what it means for dy/dt to be zero.
The graph is a cosine curve about the line y=5, with amplitude 4.9, so the water level varies between 0.1 and 9.9 feet.
Its period is the time T with 6πT=2π, so T=12 hours.
It starts at its highest, 9.9 feet, at midnight.
import numpy as np
from matplotlib import pyplot as plt
t = np.linspace(0,24,200)y =5+4.9* np.cos(np.pi * t /6)plt.plot(t, y)plt.xlabel('t (hours since midnight)')plt.ylabel('water level, y (feet)')
Using the chain rule,
dtdy=−4.9×6πsin(6πt)≈−2.57sin(6πt)
This is the rate at which the water level is rising, in feet per hour (it is falling when dy/dt is negative).
dy/dt=0 when sin(πt/6)=0, which is when πt/6 is a whole multiple of π.
So, t=0,6,12,18 and 24 hours.
At these times the water level is momentarily neither rising nor falling.
It is high tide (9.9 feet) at t=0,12 and 24, and low tide (0.1 feet) at t=6 and 18.
Main problems 4
In laminar flow of blood through a cylindrical artery, the resistance R is inversely proportional to the fourth power of the radius r.
Use a linear approximation to show that if r is decreased by 2%, R will increase by approximately 8%.
Write R=kr−4, where k is a constant.
Then
drdR=−4kr−5=−r4R
Decreasing r by 2% means a change of Δr=−0.02r.
By the linear approximation,
ΔR≈ΔrdrdR=(−0.02r)×(−r4R)=0.08R
So, R increases by approximately 8%.
(The exact increase is 1/0.984−1≈8.4%.)
Main problems 5
Imagine an ocean basin with an inlet on one side.
We can model the salinity of the water as a function of the distance from the ocean inlet.
Let s be the water salinity, and x is the distance from the inlet. Then
s=αX−xs0αX
where s0 is the initial salinity at the inlet, X is the width of the basin, and α is a constant.
Prove that the rate of increase of salinity with distance from the inlet is given by
dxds=αX−xs
Write s=s0αX(αX−x)−1, where s0αX is a constant.
By the chain rule,
dxds=s0αX×(−1)(αX−x)−2×(−1)=(αX−x)2s0αX
Splitting this into two factors,
dxds=αX−xs0αX×αX−x1=αX−xs
Main problems 6
The sine and cosine functions can be written in the form of the following infinite series:
Use the rule for differentiating inverse functions to find dy/dx for each function below, by first writing x in terms of y.
Check your answers using the standard rules.
y=x
y=x1/3
y=ln(2x)
In each case, we find dx/dy, then use
dxdy=dydx1
x=y2, so dx/dy=2y, and
dxdy=2y1=2x1
This agrees with the power rule: dxdx1/2=21x−1/2.
x=y3, so dx/dy=3y2, and
dxdy=3y21=3x2/31
This agrees with the power rule: dxdx1/3=31x−2/3.
2x=ey, so x=ey/2 and dx/dy=ey/2=x.
So,
dxdy=x1
This agrees with the chain rule: dxdln(2x)=2x1×2=x1.
It is the same as the derivative of ln(x), because ln(2x)=ln2+lnx, and the constant ln2 differentiates to zero.
Extension problems
Extension problems 1
The focal length of the lens of the eye, f(t), can be controlled so that an object at distance u(t) in front of the eye can be brought to perfect focus on the retina at a constant v=1.8cm behind the lens.
A fly is moving towards the eye at a speed of 0.7ms−1.
Assuming that the optics of the eye lens obeys the thin lens formula
f(t)1=u(t)1+v1,
find the rate of change of focal length required to keep the fly in perfect focus at a distance of 3m.
Note: consider carefully what you are differentiating with respect to, and the physical interpretation of the mathematics.
Both f and u change with time, while v is constant.
Differentiate both sides of the thin lens formula with respect to t, using the chain rule:
−f21dtdf=−u21dtdusodtdf=u2f2dtdu
Work in metres, so v=0.018m.
The fly is moving towards the eye, so u is decreasing and du/dt=−0.7ms−1.
At u=3m,
f1=31+0.0181≈55.9sof≈0.0179m
Therefore,
dtdf=320.01792×(−0.7)≈−2.5×10−5ms−1
So, the focal length must decrease at about 0.025mm per second.
Extension problems 2
A contaminated lake is treated with a bactericide.
The rate of change of harmful bacteria t days after treatment is given by
dtdN=−1+t22000t
where N(t) is the number of bacteria in 1ml of water.
State with a reason whether the count of bacteria increases or decreases during the period 0≤t≤10.
Find the minimum value of dN/dt during this period.
For 0<t≤10, the numerator 2000t and the denominator 1+t2 are both positive, so dN/dt<0.
Therefore, the count of bacteria decreases throughout this period.
To find where dN/dt is smallest, differentiate it again, using the quotient rule:
This is zero at t=1 (we ignore t=−1).
It is negative for t<1 and positive for t>1, so dN/dt has a minimum at t=1, where
dtdN=−22000=−1000
For comparison, dN/dt=0 at t=0 and dN/dt≈−198 at t=10.
So, the minimum value is −1000 bacteria per ml per day, one day after treatment, which is when the bacteria are dying fastest.
Extension problems 3
Consider a population of lions L(t) and zebra Z(t) interacting over time t.
One type of model for this situation is
dtdZ=aZ−bZLanddtdL=−cL+dZL,
where a, b, c and d are positive constants.
What values of dZ/dt and dL/dt correspond to unchanging populations?
How would the statement 'zebra go extinct' be represented mathematically?
For parameters a=0.05, b=0.001, c=0.05, and d=0.00001, find all population pairs (Z,L) that yield unchanging populations. Can both species survive together?
The populations are unchanging when both rates of change are zero: dZ/dt=0 and dL/dt=0.
Z=0, or, if the zebra die out gradually, Z(t)→0 as t→∞.
Note, if Z=0 then dL/dt=−cL, so the lions then decline too.
Factorise the two equations:
dtdZ=Z(a−bL)=0anddtdL=L(dZ−c)=0
The first is zero when Z=0 or L=a/b, and the second when L=0 or Z=c/d.
Both are zero in two cases:
Z=0 and L=0, where there are no animals at all
Z=c/d=0.05/0.00001=5000 and L=a/b=0.05/0.001=50
(If Z=0 but L=0, then dL/dt=−cL=0, so this is not a solution, and similarly for L=0 but Z=0.)
So, yes: with 5000 zebra and 50 lions, both populations stay the same, so the two species can survive together.
What happens to populations that start elsewhere needs the phase plane methods we cover later in the course.