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 3
Learning outcomes
Be able to calculate the derivative of exponential and logarithmic functions
Understand how to differentiate functions of multiple independent variables
Be able to calculate higher order derivatives with respect to multiple variables
YouTube lecture recording from October 2020
A recording of this lecture from October 2020; the material has changed a little since.
Why exponentials and partial derivatives?
In this lecture we use the chain rule to differentiate the exponential and logarithmic functions from the lecture on indices and logs.
We need these whenever a quantity grows or decays (e.g. e−kt).
We then look at functions of more than one variable (e.g. the temperature at each point on a plate).
We often want to know how such a function changes when just one of its variables changes.
This is called partial differentiation, and we will need it when we study systems of differential equations.
Examples of applying chain rule to the exponential function
y=e−ax
Let u=−ax, so du/dx=−a. Thus y=eu and
dudy=eu⇒dxdy=dudy×dxdu=eu×(−a)=−ae−ax.
y=ex2
Then, letting u=x2:
dxdex2=dxdy=dudy×dxdu=eu⋅2x=ex2⋅2x.
So an important generalisation is:
dxdef(x)=ef(x)f′(x)
for any function f(x).
Example with the natural logarithm
y=ln((a−x)2)=2ln∣a−x∣=2ln∣u∣.
Let u=(a−x):
⇒dxdu=−1anddudy=u2Thusdxdy=u2×(−1)=a−x−2
This also generalises:
dxdln(f(x))=f(x)f′(x)
The derivative of ax
For a>0, by the properties of logarithms and indices we have
ax=(elna)x=e(x⋅lna).
Thus, as we saw above we have:
dxdax=dxde(x⋅lna)=e(x⋅lna)dxd(x⋅lna)=ax⋅lna
So, at x=0, where ax=1, the gradient of ax is just lna.
The following plot shows this for a=2, where the gradient is ln2≈0.69.
For ex (in grey) the gradient at x=0 is lne=1, and e is the only base for which this is the case.
Similarly, in general:
dxdaf(x)=af(x)⋅lna⋅f′(x)
SymPy example
Let's try and use SymPy to check this:
import sympy as sp
x, a = sp.symbols('x a')# declare the variables x and af = sp.Function('f')# declare a function dependent on another variablesp.diff(a**f(x),x)# write the expression we wish to evaluate
af(x)log(a)dxdf(x)
(SymPy writes log for the natural logarithm, ln.)
The derivative of logax
For a>0, a=1, recall the conversion formula logax=lnx/lna and note that lna is a constant.
Thus:
x, a = sp.symbols('x a')# declare the variables x and af = sp.Function('f')# declare a function dependent on another variablesp.diff(sp.log(f(x),a),x)# write the expression we wish to evaluate
f(x)log(a)dxdf(x)
Further examples
Product rule: let y=x2ex. Then:
dxdy=dxdx2ex=dxdx2⋅ex+x2⋅dxdex=(2x+x2)ex
Quotient rule: let y=ex/x. Then:
dxdy=x2dxdex⋅x−ex⋅dxdx=x2ex⋅x−ex⋅1=x2x−1ex
Chain rule: y=ex2. Then, letting f(x)=x2:
dxdex2=ef(x)f′(x)=ex2⋅2x
y=ln(x2+1). Then, letting f(x)=x2+1:
dxdln(x2+1)=f(x)f′(x)=x2+12x
dxd2x3=2x3⋅ln2⋅3x2
dxd10x2+1=10x2+1⋅ln10⋅2x
dxdlog10(7x+5)=(7x+5)⋅ln107
dxdlog2(3x+x4)=ln2⋅(3x+x4)3x⋅ln3+4x3
Functions of several variables: partial differentiation
Definition: Given a function z=f(x,y) of two variables x and y, the partial derivative of z with respect to x is the function obtained by differentiating f(x,y) with respect to x, holding y constant.
We denote this using ∂ (a "curly" d, sometimes pronounced "del") as shown below:
∂x∂z=∂x∂f(x,y)=fx(x,y)
Example 1
f(x,y)=z=x2−2y2fx=∂x∂z=2xandfy=∂y∂z=−4y
To see what holding y constant means, imagine slicing through the surface z=x2−2y2 with the plane y=1 (on the left, below).
The slice is the curve z=x2−2 (on the right), which is an ordinary function of x.
Its gradient at any point is fx=2x, so at x=1 it is 2.
Moving the plane to a different value of y moves the curve up or down, but does not change its gradient, because fx does not depend on y.
Example 2
Let z=3x2y+5xy2. Then the partial derivative of z with respect to x, holding y fixed, is:
∂x∂z=∂x∂(3x2y+5xy2)=3y⋅2x+5y2⋅1=6xy+5y2
while the partial of z with respect to y holding x fixed is:
∂y∂z=∂y∂(3x2y+5xy2)=3x2⋅1+5x⋅2y=3x2+10xy
SymPy example
Above, we had:
∂x∂(3x2y+5xy2)=6xy+5y2
Let's redo this in SymPy:
x, y = sp.symbols('x y')sp.diff(3*x**2*y +5*x*y**2,x)
6xy+5y2
Higher-order partial derivatives
Given z=f(x,y) there are now four distinct possibilities for the
second-order partial derivatives.
With respect to x twice:
∂x∂(∂x∂z)=∂x2∂2z=zxx
With respect to y twice:
∂y∂(∂y∂z)=∂y2∂2z=zyy
First with respect to x, then with respect to y:
∂y∂(∂x∂z)=∂y∂x∂2z=zxy
First with respect to y, then with respect to x:
∂x∂(∂y∂z)=∂x∂y∂2z=zyx
Example: Laplace's equation for equilibrium temperature distribution on a copper plate
Let T(x,y) give the temperature at the point (x,y).
According to a result of the French mathematician Pierre-Simon Laplace (1749 - 1827), at every point (x,y) the second-order partials of T must satisfy the equation:
Txx+Tyy=0
We can verify that the function T(x,y)=y2−x2 satisfies Laplace's equation:
First with respect to x:
Tx(x,y)=0−2x=−2xsoTxx(x,y)=−2
Then with respect to y:
Ty(x,y)=2y−0=2ysoTyy(x,y)=2
Finally:
Txx(x,y)+Tyy(x,y)=−2+2=0
which proves the result.
The following plot shows this temperature on a square plate, with −1≤x≤1 and −1≤y≤1.
It is the temperature that the plate settles to when its top and bottom edges are held warm and its left and right edges are held cold.
(Only differences in temperature matter here, so a negative value of T just means colder than some reference temperature.)
Note that the hottest and coldest points are on the edges of the plate.
A solution of Laplace's equation can never have a hot or cold spot inside the plate.
The function z=x2y−xy2 does not satisfy Laplace's equation (and so cannot be a model for thermal equilibrium).
First note that
zxzxx=2xy−y2=2y
and that
zyzyy=x2−2xy=−2x
Therefore:
zxx+zyy=2y−2x
which is not zero everywhere (it is only zero on the line y=x).
We can also verify this in SymPy like so:
T1 = y**2- x**2sp.diff(T1, x, x)+ sp.diff(T1, y, y)
0
and for the second function:
T2 = x**2*y - x*y**2sp.diff(T2, x, x)+ sp.diff(T2, y, y)
−2x+2y
A note on the mixed partials fxy and fyx
For almost any function you will meet, fxy=fyx, so it does not matter in which order we take the partial derivatives (there are exceptions, but you are unlikely to meet them).
Example
Let z=x2y3+3x2−2y4. Then zx=2xy3+6x and zy=3x2y2−8y3.
Taking the partial of zx with respect to y we get
zxy=∂y∂(2xy3+6x)=6xy2
Taking the partial of zy with respect to x we get the same thing:
zyx=∂x∂(3x2y2−8y3)=6xy2
So the operators ∂/∂x and ∂/∂y are commutative:
i.e.∂x∂(∂y∂z)=∂y∂(∂x∂z)
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 chemistry problems on partial derivatives, 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 with respect to x, using the stated rules where indicated:
Product rule: xex
Product rule: 3x2ln(x)
Chain rule: e−4x3
Chain rule: lnx3/2/6
Chain rule: 10x2
Any rules: lnx/(5x−7)
Any rules: ex/(2x3−1)
Any rules: log2(xcos(x))
By the product rule,
dxd(xex)=2x1ex+xex=ex(2x1+x)
By the product rule,
dxd(3x2ln(x))=6xln(x)+3x2⋅x1=6xln(x)+3x
Let u=−4x3, so that du/dx=−12x2. Then
dxd(e−4x3)=eudxdu=−12x2e−4x3
It is easiest to simplify first, using the laws of logarithms:
lnx3/2/6=21(ln(x3/2)−ln(6))=43ln(x)−21ln(6)
The second term is a constant, so
dxd(lnx3/2/6)=4x3
(The chain rule gives the same answer, with more work.)
Let u=x2, so that du/dx=2x. Using the derivative of au,
Find the partial derivatives fx and fy of the following functions:
f(x,y)=x3+4xy2−y4
f(x,y)=e2xsin(y)
f(x,y)=ln(x2+y2)
Holding y constant, then holding x constant:
fx=3x2+4y2andfy=8xy−4y3
When we differentiate with respect to x, sin(y) is a constant, and when we differentiate with respect to y, e2x is a constant:
fx=2e2xsin(y)andfy=e2xcos(y)
Use the chain rule, with u=x2+y2:
fx=x2+y21×2x=x2+y22xandfy=x2+y22y
Main problems
Main problems 1
The power, W, that a certain machine develops is given by the formula
W=EI−RI2
where I is the current and E and R are positive constants.
Find the maximum value of W as I varies.
dIdW=E−2RI=0⟹I=2RE
To show this is a maximum, we check the second derivative:
dI2d2W=−2R<0
since R is positive.
So the maximum power is
W=E⋅2RE−R(2RE)2=2RE2−4RE2=4RE2
Main problems 2
Environmental health officers monitoring an outbreak of food poisoning after a wedding banquet were able to model the time course of the recovery of the guests using the equation:
r=1+t100t
where t represents the number of days since infection and r is the percentage of guests who no longer display symptoms.
Determine an expression for the rate of recovery.
The rate of recovery is dr/dt.
By the quotient rule,
dtdr=(1+t)2100(1+t)−100t=(1+t)2100
in percent of guests per day.
This is largest at t=0 (100% per day), and gets smaller as time goes on, so the guests recover quickly at first and then more slowly.
Main problems 3
An experiment called 'the reptilian drag race' looks at how agamid lizards accelerate from a standing start.
The distance x travelled in time t on a horizontal surface has been modelled as
x=vmax(t+ke−kt−k1),
where vmax is the maximum velocity, and k is a rate constant.
Find expressions for the velocity v and acceleration a as functions of time.
For vmax=3ms−1 and k=10s−1, sketch x, v and a/10 on the same axes for 0≤t≤1s.
Differentiating once and then again,
v=dtdx=vmax(1−e−kt)anda=dtdv=vmaxke−kt
So the lizard starts from rest, and its velocity approaches vmax as t increases.
With these values, x=3(t+e−10t/10−1/10), v=3(1−e−10t) and a/10=3e−10t.
x starts at 0 with zero gradient, curves upwards, and soon becomes close to a straight line of gradient 3, reaching about 2.7 m at t=1s.
v rises from 0 towards 3 ms−1, and is already at 95% of this by t=0.3s.
a/10 starts at 3 and decays towards 0, so the lizard does almost all of its accelerating in the first few tenths of a second.
import numpy as np
from matplotlib import pyplot as plt
v_max =3k =10t = np.linspace(0,1,200)x = v_max *(t + np.exp(-k * t)/ k -1/ k)v = v_max *(1- np.exp(-k * t))a = v_max * k * np.exp(-k * t)plt.plot(t, x, label='x (m)')plt.plot(t, v, label='v (m/s)')plt.plot(t, a /10, label='a/10 (m/s$^2$)')plt.xlabel('t (s)')plt.legend()
Main problems 4
The distance x that a particular organism travels over time from its starting location is modelled by the equation
x(t)=t2ek(1−t),
where k is a positive constant and 0≤t≤1s.
Sketch x over time for k=1/2 and k=3.
Calculate an expression for the organism's velocity as a function of time.
What is the largest value of k such that the organism never starts moving back towards where it started?
For every k, x(0)=0 and x(1)=1.
For k=1/2, x increases all the way from 0 to 1.
For k=3, x rises to a maximum of (4/9)e≈1.21 at t=2/3 (see part 2.), then falls back to 1 at t=1.
import numpy as np
from matplotlib import pyplot as plt
t = np.linspace(0,1,200)for k in[0.5,3]: plt.plot(t, t**2* np.exp(k *(1- t)), label=f'k = {k}')plt.xlabel('t (s)')plt.ylabel('x')plt.legend()
By the product rule and the chain rule,
v=dtdx=2tek(1−t)+t2(−k)ek(1−t)=t(2−kt)ek(1−t)
The organism moves back towards its start when v<0.
For 0<t≤1, both t and ek(1−t) are positive, so v has the same sign as 2−kt.
This means that v<0 when t>2/k.
So, the organism never moves back during 0≤t≤1 if 2/k≥1, i.e. if k≤2.
The largest value is k=2.
Main problems 5
The function
S=Smax(1−e−t/τ)
is used to describe sediment thickness accumulating in an extensional basin through time.
What is the sedimentation rate?
The sedimentation rate is dS/dt.
By the chain rule,
dtdS=Smax⋅(−e−t/τ)⋅(−τ1)=τSmaxe−t/τ
The rate starts at Smax/τ, and decreases towards zero as the thickness approaches Smax.
Main problems 6
Which of these functions could describe the equilibrium temperature T(x,y) of a copper plate?
That is, which satisfy Laplace's equation, Txx+Tyy=0?
T=x3−3xy2
T=exsin(y)
T=x2+y2
T=ln(x2+y2), for (x,y)=(0,0)
Tx=3x2−3y2, so Txx=6x.
Ty=−6xy, so Tyy=−6x.
So, Txx+Tyy=6x−6x=0, and T satisfies Laplace's equation.
Txx=exsin(y) and Tyy=−exsin(y).
So, Txx+Tyy=0, and T satisfies Laplace's equation.
Txx=2 and Tyy=2.
So, Txx+Tyy=4, which is not zero, and T does not satisfy Laplace's equation.
From Introductory problems 4, Tx=2x/(x2+y2).
Using the quotient rule,
Txx=(x2+y2)22(x2+y2)−2x×2x=(x2+y2)22(y2−x2)
In the same way, Ty=2y/(x2+y2), and
Tyy=(x2+y2)22(x2−y2)
These add to zero, so T satisfies Laplace's equation (everywhere except the origin, where it is not defined).
Extension problems
Extension problems 1
Let
z=32x3−43x2y+52y3.
Find zx and zy
Find zxx and zyy
Show that zxy=zyx
Treating y as a constant, and then x as a constant,
zx=2x2−23xyandzy=−43x2+56y2
Differentiating again with respect to the same variable,
zxx=4x−23yandzyy=512y
Differentiating zx with respect to y, and zy with respect to x,
zxy=−23xandzyx=−23x
so zxy=zyx.
Extension problems 2
Show that fxy=fyx for the following functions:
f(x,y)=x2−xy+y3
f(x,y)=eyln(2x−y)
f(x,y)=2xye2xy
f(x,y)=xsin(y)
In each case we find fx and fy, then differentiate fx with respect to y and fy with respect to x.
Swapping the roles of x and y in this working gives fyx, and the result is unchanged, so fxy=fyx.
fx=sin(y) and fy=xcos(y), so fxy=cos(y) and fyx=cos(y).
Extension problems 3
The body mass index, B, is used as a parameter to classify people as underweight, normal, overweight and obese.
It is defined as their weight in kg, w, divided by the square of their height in metres, h.
Sketch a graph of B against w for a person who is 1.7m tall.
Find the rate of change of B with weight of this person.
Sketch a graph of B against h for a child whose weight is constant at 35 kg.
Find the rate of change of B with height h of this child.
Show that
∂h∂w∂2B=∂w∂h∂2B.
We have B=w/h2.
With h=1.7, B=w/1.72≈0.346w, which is a straight line through the origin with gradient about 0.346.
import numpy as np
from matplotlib import pyplot as plt
w = np.linspace(40,120,100)plt.plot(w, w /1.7**2)plt.xlabel('w (kg)')plt.ylabel('B')
Treating h as a constant,
∂w∂B=h21=1.721≈0.346m−2
So this person's BMI rises by about 0.35 for each extra kg.
With w=35, B=35/h2.
This is a decreasing curve: B is large for small h, and falls towards zero as h increases (for example, B≈17.9 at h=1.4).
h = np.linspace(1,1.8,100)plt.plot(h,35/ h**2)plt.xlabel('h (m)')plt.ylabel('B')
Treating w as a constant,
∂h∂B=−h32w=−h370
in kgm−3.
For example, at h=1.4 this is about −25.5, so the child's BMI falls by about 0.26 for each extra cm of height.
Differentiating ∂B/∂w=1/h2 with respect to h, and ∂B/∂h=−2w/h3 with respect to w,
∂h∂w∂2B=−h32and∂w∂h∂2B=−h32
so the two are equal.
Extension problems 4
A light wave or a sound wave propagated through time and space can be represented in a simplified form by:
y=Asin(2π(λx+ft))
where A is the amplitude, λ is the wavelength and f is the frequency of the wave.
x and t are position and time respectively.
An understanding of this function is essential for many problems such as sound, light microscopy, phase microscopy and X-ray diffraction.
Draw a graph of y as a function of x assuming t=0.
Draw a graph of y as a function of t assuming x=0.
At what values of x and t does the function repeat itself?
Find the rate at which y changes at an arbitrary fixed position.
Show that yxt=ytx.
At t=0, y=Asin(2πx/λ).
This is a sine wave in x with amplitude A, which is zero at x=0,λ/2,λ,… and repeats every λ.
At x=0, y=Asin(2πft).
This is a sine wave in t with amplitude A, which repeats every 1/f.
import numpy as np
from matplotlib import pyplot as plt
A =1wavelength =2f =0.5x = np.linspace(0,3* wavelength,300)t = np.linspace(0,3/ f,300)plt.subplot(1,2,1)plt.plot(x, A * np.sin(2* np.pi * x / wavelength))plt.xlabel('x (at t = 0)')plt.subplot(1,2,2)plt.plot(t, A * np.sin(2* np.pi * f * t))plt.xlabel('t (at x = 0)')
The sine function repeats when its argument increases by 2π.
Increasing x by λ adds 2π to the argument, and so does increasing t by 1/f.
So, the function repeats every wavelength λ in x, and every period 1/f in t.
At a fixed position we treat x as a constant, so the rate of change is