Skip to main content
Differentiation 2
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 2


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 these rules?

In the last lecture we found the derivative of axnax^n.
Most functions we meet are built from simpler ones, by multiplying them, dividing them, or putting one inside another (e.g. 1+x2\sqrt{1+x^2}). 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.
ddx(xn)=nxn−1ddx(sin⁡x)=cos⁡xddx(cos⁡x)=−sin⁡xddx(ex)=exddx(ln⁡x)=1x\begin{aligned} \frac{d}{dx} (x^n) &= n x^{n-1} \\ \frac{d}{dx} (\sin x) &= \cos x \\ \frac{d}{dx} (\cos x) &= -\sin x \\ \frac{d}{dx} (e^x) &= e^x \\ \frac{d}{dx} (\ln x) &= \frac{1}{x} \end{aligned}
For sin⁡\sin and cos⁡\cos, xx must be in radians. We show the derivative of ln⁡x\ln x 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).
Graph of sin and cos

Differentiation of sums and scalar multiples

(f(x)±g(x))′=f′(x)±g′(x)(af(x))′=af′(x)\begin{aligned} (f(x) \pm g(x))' &= f'(x) \pm g'(x) \\ (a f(x))' &= a f'(x) \end{aligned}

Differentiation of products

While differentiating sums, and scalar multiples is straightforward, differentiating products is more complex
(f(x)g(x))′≠f′(x)g′(x)(f(x)g(x))′=f′(x)g(x)+g′(x)f(x)\begin{aligned} (f(x) g(x) )' &\neq f'(x) g'(x) \\ (f(x) g(x) )' &= f'(x) g(x) + g'(x) f(x) \end{aligned}

Example

To illustrate that this works, consider y=(2x3−1)(3x3+2x)y = (2x^3 - 1)(3x^3 + 2x)
If we expand this out, we have that y=6x6+4x4−3x3−2xy = 6x^6 + 4x^4 - 3x^3 - 2x
From this, clearly, y′=36x5+16x3−9x2−2y' = 36 x^5 + 16x^3 - 9 x^2 - 2
To use the product rule, instead we say y=f×gy = f \times g, where f=2x3−1f = 2x^3 - 1, and g=3x3+2xg = 3x^3 + 2x. Therefore
f′(x)=6x2g′(x)=9x2+2y′=f′g+g′f=6x2(3x3+2x)+(9x2+2)(2x3−1)y′=18x5+12x3+18x5+4x3−9x2−2=36x5+16x3−9x2−2\begin{aligned} f'(x) &= 6x^2 \\ g'(x) &= 9x^2 + 2 \\ y' &= f'g + g'f = 6x^2 (3x^3 + 2x) + (9x^2 + 2)(2x^3 - 1) \\ y' &= 18x^5 + 12x^3 + 18x^5 + 4x^3 - 9x^2 - 2 = 36x^5 + 16x^3 - 9x^2 - 2 \end{aligned}
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))y = f(g(x)). For this we use the chain rule:
y=f(g(x))y′(x)=f′(g(x)) g′(x)=dfdgdgdx\begin{aligned} y &= f(g(x)) \\ y'(x) &= f'(g(x))\, g'(x) = \frac{df}{dg} \frac{dg}{dx} \end{aligned}

Example 1: y=(5x2+2)4y = (5x^2 + 2)^4

We can write this as y=g4y = g^4, where g=5x2+2g = 5x^2 + 2. Given this, we have that
dydg=4g3=4(5x2+2)3dgdx=10x\begin{aligned} \frac{dy}{dg} &= 4g^3 = 4(5x^2 + 2)^3 \\ \frac{dg}{dx} &= 10x \end{aligned}
This means that
dydx=dydgdgdx=4(5x2+2)310x=40x(5x2+2)3\frac{dy}{dx} = \frac{dy}{dg} \frac{dg}{dx} = 4 (5x^2 + 2)^3 10 x = 40 x (5x^2 + 2)^3
This extends to any number of nested functions, meaning
ddx a(b(c(x)))=dadbddx b(c(x))=dadbdbdcdcdx\frac{d}{dx}\,a(b(c(x))) = \frac{da}{db} \frac{d}{dx}\,b(c(x)) = \frac{da}{db} \frac{db}{dc}\frac{dc}{dx}

Differentiating the ratio of two functions: the quotient rule

If y(x)=f(x)/g(x)y(x) = f(x)/g(x), then by using the product and chain rules on f(x) (g(x))−1f(x)\,(g(x))^{-1}, we can show that
y′(x)=f′g−g′fg2y'(x) = \frac{f'g - g'f}{g^2}

Example

y=3x−14x+2y = \frac{3x-1}{4x + 2} f=3x−1,f′=3g=4x+2,g′=4y′=f′g−g′fg2=3(4x+2)−4(3x−1)(4x+2)2y′=12x+6−12x+4(4x+2)2=10(4x+2)2\begin{aligned} f &= 3x - 1, \quad f' = 3 \\ g &= 4x + 2, \quad g' = 4 \\ y' &= \frac{f'g - g'f}{g^2} = \frac{3(4x+2) - 4(3x-1)}{(4x+2)^2} \\ y' &= \frac{12x + 6 - 12 x + 4}{(4x+2)^2} = \frac{10}{(4x+2)^2} \end{aligned}

Differentiating inverse functions

For any function y=f(x)y = f(x), with a well defined inverse f−1(x)f^{-1}(x) (not to be confused with (f(x))−1(f(x))^{-1}), we have by definition that
x=f−1(f(x))=f−1(y).x = f^{-1}(f(x)) = f^{-1}(y).
This means that we can apply the chain rule
ddx(x)=ddx(f−1(y))=ddy(f−1(y))dydx\frac{d}{dx}(x) = \frac{d}{dx}(f^{-1}(y)) = \frac{d}{dy}(f^{-1}(y)) \frac{dy}{dx}
But since d(x)/dx=1d(x)/dx = 1
ddy(f−1(y))=1dydx(where dy/dx≠0)\frac{d}{dy}(f^{-1}(y)) = \frac{1}{\frac{dy}{dx}} \qquad \text{(where } dy/dx \neq 0\text{)}
(This is an example of implicit differentiation, where we differentiate both sides of an equation relating xx and yy.)

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

If y=ln⁡(x)y = \ln(x), this means that f−1(y)=ey=xf^{-1}(y) = e^y = x
Since eye^y is unchanged when differentiated, ddy(f−1(y))=ey\frac{d}{dy}(f^{-1}(y)) = e^y. This means that
ddx(ln⁡(x))=1ddy(f−1(y))=1ey\frac{d}{dx}(\ln(x)) = \frac{1}{\frac{d}{dy}(f^{-1}(y))} = \frac{1}{e^y}
But since y=ln⁡(x)y = \ln(x):
ddx(ln⁡(x))=1eln⁡(x)=1x\frac{d}{dx}(\ln(x)) = \frac{1}{e^{\ln(x)}} = \frac{1}{x}

Linear approximation and the derivative

By definition, the derivative of a function f(x)f(x) is
f′(x)=lim⁡h→0f(x+h)−f(x)hf'(x) = \lim_{h \rightarrow 0} \frac{f(x+h) - f(x)}{h}
This means that for small hh, this expression approximates the derivative. By rearranging this, we have
f(x+h)≈f(x)+hf′(x)f(x + h) \approx f(x) + h f'(x)
In other words, f(x+h)f(x+h) can be approximated by starting at f(x)f(x) and moving a horizontal distance hh along the tangent, whose gradient is f′(x)f'(x).

Example

Estimate 5218\sqrt{5218}
To do this, we first need an f(x)f(x) that is easy to calculate, and close to 5218. For this we can take that 702=490070^2 = 4900.
To calculate the approximation, we need f′(x)f'(x), where f(x)=xf(x) = \sqrt{x}.
f′(x)=12xf'(x) = \frac{1}{2 \sqrt{x}}
Since 5218 = 4900 + 318, we can set x=4900x = 4900 and h=318h = 318.
Using the approximation, we have:
f(5218)≈f(4900)+318×f′(4900)f(5218)≈70+318×1140≈72.27\begin{aligned} f(5218) &\approx f(4900) + 318 \times f'(4900) \\ f(5218) &\approx 70 + 318 \times \frac{1}{140} \approx 72.27 \end{aligned}
5218=72.2357252\sqrt{5218} = 72.2357252 - not a bad approximation!

Example: differentiating using SymPy

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^2 sp.diff(x**2, x)
2x2 x
sp.diff(sp.cos(x), x)
−sin⁡(x)- \sin{\left(x \right)}
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)- 2 x \left(x + 1\right)^{3} \sin{\left(x^{2} - 5 \right)} + 3 \left(x + 1\right)^{2} \cos{\left(x^{2} - 5 \right)}
f = (x+1)**3 * (x-2)**2 * (x**2 + 4*x + 1)**4 sp.diff(f, x)
(x−2)2(x+1)3(8x+16)(x2+4x+1)3+3(x−2)2(x+1)2(x2+4x+1)4+(x+1)3(2x−4)(x2+4x+1)4\begin{aligned} &\left(x - 2\right)^{2} \left(x + 1\right)^{3} \left(8 x + 16\right) \left(x^{2} + 4 x + 1\right)^{3} \\ &+ 3 \left(x - 2\right)^{2} \left(x + 1\right)^{2} \left(x^{2} + 4 x + 1\right)^{4} \\ &+ \left(x + 1\right)^{3} \left(2 x - 4\right) \left(x^{2} + 4 x + 1\right)^{4} \end{aligned}
sp.expand(sp.diff(f, x)) # expand out in polynomial form
13x12+180x11+869x10+1250x9−2934x8−11504x7−9142x6+10092x5+23185x4+17068x3+6081x2+1058x+72\begin{aligned} &13 x^{12} + 180 x^{11} + 869 x^{10} + 1250 x^{9} - 2934 x^{8} - 11504 x^{7} - 9142 x^{6} \\ &+ 10092 x^{5} + 23185 x^{4} + 17068 x^{3} + 6081 x^{2} + 1058 x + 72 \end{aligned}

SymPy documentation

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:
  1. Product rule: y=(3x+4x2)(8+3x2)y=(3x+4x^2)(8+3x^2)
  2. Product rule: y=(5x2−12)(4x−1+2)y=(5x^2-12)(4x^{-1} +2)
  3. Product rule: y=x cos⁡xy=x\,\cos x
  4. Product rule: y=(3x+4x3)sin⁡xy=(3\sqrt{x} + 4x^3)\sin x
  5. Chain rule: y=(6x+2)4y=(6x+2)^4
  6. Chain rule: y=(5x3+10)1/2y=(5x^3+10)^{1/2}
  7. Any rules: y=1/(1−3x)y=\sqrt{1/(1-3x)}
  8. Any rules: y=(3x+1)5x2−xy=(3x+1)\sqrt{5x^2-x}

Introductory problems 2

Differentiate the following trigonometric functions with respect to xx:
  1. 3sin⁡(x)+5cos⁡(x)3\sin(x) + 5\cos(x)
  2. cos⁡(3−2x)\cos(3-2x)
  3. sin⁡(x)\sqrt{\sin(x)}
  4. cos⁡(x)/(4x)\cos(x)/(4x)

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?

Main problems

Main problems 1

Let y=x2y=x^2.
  1. Find the exact value of yy when x=2.1x=2.1.
  2. Now estimate the value of yy when x=2.1x=2.1 by using the linear approximation formula
    f(x1+h)≈f(x1)+hf′(x1)f(x_1+h)\approx f(x_1)+hf'(x_1)
    and letting x1=2.0x_1=2.0 and h=0.1h=0.1.
  3. Compare your estimate to the true value. Which is bigger? What is there about the shape of the graph of y=x2y=x^2 that accounts for this?
  4. Repeat parts 1. and 2. for x=2.01x=2.01.
  5. Calculate the absolute error in each estimate. How does this error change with the value of hh?

Main problems 2

The energy, EE, carried by a photon of wavelength λ\lambda is given by
E=hcλE=\frac{hc}{\lambda}
where hh is Planck's constant (h=6.63×10−34 Jsh=6.63\times 10^{-34}\,\text{Js}) and cc is the speed of light (c=3×108 ms−1c=3 \times 10^8\,\text{ms}^{-1}).
  1. Calculate the energy carried by a photon of wavelength 500 nm500\,\text{nm}.
  2. Sketch a graph to show how E varies with λ\lambda.
  3. Derive an expression for dE/dλdE/d\lambda, and calculate the slope of your graph when λ=500 nm\lambda=500\,\text{nm}.
  4. Hence, or otherwise, estimate the difference in energy between a photon of wavelength 500 nm500\,\text{nm} and one of wavelength 505 nm505\,\text{nm}.

Main problems 3

On February 10, 1990, the water level in Boston harbour was given by:
y=5+4.9cos⁡(π6t)y=5 + 4.9 \cos\left(\frac{\pi}{6} t\right)
where tt is the number of hours since midnight and yy is measured in feet.
  1. Sketch y.
  2. Find dy/dtdy/dt. What does it represent, in terms of water level?
  3. For 0≤t≤240\le t \le 24, when is dy/dtdy/dt zero? Explain what it means for dy/dtdy/dt to be zero.

Main problems 4

In laminar flow of blood through a cylindrical artery, the resistance RR is inversely proportional to the fourth power of the radius rr.
Use a linear approximation to show that if rr is decreased by 2%, RR will increase by approximately 8%.

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 ss be the water salinity, and xx is the distance from the inlet. Then
s=s0αXαX−xs = \frac{s_{0}\alpha X}{\alpha X - x}
where s0s_{0} is the initial salinity at the inlet, XX is the width of the basin, and α\alpha is a constant.
Prove that the rate of increase of salinity with distance from the inlet is given by
dsdx=sαX−x\frac{ds}{dx} = \frac{s}{\alpha X - x}

Main problems 6

The sine and cosine functions can be written in the form of the following infinite series:
sin⁡x=x−x33!+x55!−x77!+…cos⁡x=1−x22!+x44!−x66!+…\begin{aligned} \sin x &= x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \ldots \\ \cos x &= 1 - \frac{x^2}{2!} + \frac{x^4}{4!} - \frac{x^6}{6!} + \ldots \end{aligned}
Here n!n! (read "nn factorial") is the product of the whole numbers from nn down to 1, so for example 3!=3×2×1=63! = 3 \times 2 \times 1 = 6.
Differentiate these series term by term to verify the standard expressions for the derivatives of sin⁡x\sin x and cos⁡x\cos x.

Main problems 7

Use the rule for differentiating inverse functions to find dy/dxdy/dx for each function below, by first writing xx in terms of yy. Check your answers using the standard rules.
  1. y=xy = \sqrt{x}
  2. y=x1/3y = x^{1/3}
  3. y=ln⁡(2x)y = \ln(2x)

Extension problems

Extension problems 1

The focal length of the lens of the eye, f(t)f(t), can be controlled so that an object at distance u(t)u(t) in front of the eye can be brought to perfect focus on the retina at a constant v=1.8 cmv = 1.8\,\text{cm} behind the lens.
A fly is moving towards the eye at a speed of 0.7 ms−10.7\,\text{ms}^{-1}.
Assuming that the optics of the eye lens obeys the thin lens formula
1f(t)=1u(t)+1v,\frac{1}{f(t)}=\frac{1}{u(t)}+\frac{1}{v},
find the rate of change of focal length required to keep the fly in perfect focus at a distance of 3 m3\,\text{m}.
Note: consider carefully what you are differentiating with respect to, and the physical interpretation of the mathematics.

Extension problems 2

A contaminated lake is treated with a bactericide.
The rate of change of harmful bacteria tt days after treatment is given by
dNdt=−2000t1+t2\frac{dN}{dt} = -\frac{2000t}{1+t^2}
where N(t)N(t) is the number of bacteria in 1 ml1\,\text{ml} of water.
  1. State with a reason whether the count of bacteria increases or decreases during the period 0≤t≤100\leq t \leq 10.
  2. Find the minimum value of dN/dtdN/dt during this period.

Extension problems 3

Consider a population of lions L(t)L(t) and zebra Z(t)Z(t) interacting over time tt. One type of model for this situation is
dZdt=aZ−bZLanddLdt=−cL+dZL,\frac{dZ}{dt} = aZ - bZL \qquad \text{and} \qquad \frac{dL}{dt} = -cL + dZL,
where aa, bb, cc and dd are positive constants.
  1. What values of dZ/dtdZ/dt and dL/dtdL/dt correspond to unchanging populations?
  2. How would the statement 'zebra go extinct' be represented mathematically?
  3. For parameters a=0.05a=0.05, b=0.001b=0.001, c=0.05c=0.05, and d=0.00001d=0.00001, find all population pairs (Z,L)(Z,L) that yield unchanging populations. Can both species survive together?