Skip to main content

Scientific Computing

Essential Maths

Differential ... []

Scientific Computing

Essential Maths

Differential ... []

This material has been adapted from material by Fergus Cooper from the "Essential Mathematics" module of the SABS R³ Center for Doctoral Training.

This material has been adapted from material by Fergus Cooper from the "Essential Mathematics" module of the SABS R³ Center for Doctoral Training.

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

Differential equations 2


YouTube lecture recording from October 2020

The following YouTube video was recorded for the 2020 iteration of the course. The material is still very similar:

Youtube lecture thumbnail


From Words to Maths

How do we form differential equations from words?

Example 1: a growing leaf

Let us try to form a differential equation based on the following information:


The length   y  \;y\; cm of a leaf during the period of its growth is proportional to the amount of water it contains. During this period the leaf retains a similar shape: that is, the ratio of its length to its width remains constant. The leaf absorbs water from its plant at a rate proportional to   y  \;y\; and it loses water by evaporation at a rate proportional to the area of the leaf at the time when its length is   y  \;y\; cm.


  1. Assume the length of the leaf is   y  \;y\; cm at time   t  \;t\; days after it was first observed.

  2. Let the rate the leaf receives water be   k1y  \;k_1y\; where   k1  \;k_1\; is a positive constant.

  3. Area of leaf at time   t  \;t\; days is proportional to   y2  \;y^2\; since it maintains its shape, so the leaf is losing water at a rate of   k2y2  \;k_2y^2\; where   k2  \;k_2\; is another positive constant.

The rate of growth is given by dydt\displaystyle{ {\rm d}y\over {\rm d}t}, which is the rate of change of its length.

dydt=k1yk2y2=y(k1k2y)\displaystyle{{\rm d}y\over {\rm d}t}=k_1y-k_2y^2=y(k_1-k_2y)

When k1k_1 and k2k_2 are both equal to 1.01.0, the solution looks like:

Solution when k1 and k2 are both equal to 1.0

Example 2: solid tumour growth


An avascular tumour tends to grow in a spherical shape, depending on environmental restrictions.

Assuming that the growth rate of the tumour depends only on the availability of oxygen and nutrients, which enter the tumour solely by diffusing through its surface, derive a model for the change in tumour volume over time.


  1. Denote the volume of the tumour at time   t  \;t\; by   V(t)  \;V(t)\;, and its radius by   R(t)\;R(t).

  2. Since the tumour is a sphere, its volume   V  \;V\; is proportional to   R3  \;R^3\; and its surface area to   R2  \;R^2\;, so the surface area is proportional to   V2/3  \;V^{2/3}\;.

  3. The rate at which the tumour acquires nutrients, and hence the rate at which the volume increases, is thus proportional to   V2/3\;V^{2/3}.

This gives us the equation:

dVdt=kV2/3\displaystyle\frac{{\rm d}V}{{\rm d}t} = kV^{2/3} > dVdt=kV2/3\displaystyle\frac{{\rm d}V}{{\rm d}t} = kV^{2/3}

Solve by separation of variables:

V2/3 dV=k dt\displaystyle\int V^{-2/3}~{\rm d}V = \int k~{\rm d}t > V=(kt+c3)3\displaystyle V = \left({kt+c\over 3}\right)^3

where cc is a constant of integration, the value of which will depend upon the initial conditions.

When k=1k=1 and c=10c=10, the solution looks like:

Solution when k=1 and c=10

Second Order Differential Equations

Let us try to solve the following equation:

d2ydx2=(dydx)2\displaystyle \frac{{\rm d}^2y}{{\rm d}x^2} = \left(\frac{{\rm d}y}{{\rm d}x}\right)^2

We will use the substitution z=dydx\displaystyle z = \frac{{\rm d}y}{{\rm d}x}. This implies that dzdx=d2ydx2\displaystyle \frac{{\rm d}z}{{\rm d}x} = \frac{{\rm d}^2y}{{\rm d}x^2}.

Substituting into the original equation, to eliminate yy, gives

dzdx=z2\displaystyle \frac{{\rm d}z}{{\rm d}x} = z^2

This is a separable equation:

z2 dz= dx1z=x+Az=1x+A\displaystyle \int z^{-2}~{\rm d}z = \int ~{\rm d}x \qquad\Rightarrow\qquad-{1\over z} = x + A \qquad\Rightarrow\qquad z = -{1\over x+A}

where AA is an arbitrary constant.

We can then replace zz using the original substitution to obtain a first order differential equation:

dydx=1x+A\displaystyle \frac{{\rm d}y}{{\rm d}x} = -{1\over x+A}

This equation can be solved with a standard integral:

y=ln(x+A)+B\displaystyle y = -\ln(x+A) + B

Determining the values of AA and BB can be done in several different ways, depending on the kind of information we have.


For example, if we know the following:

  • At   x=0,  \;x=0,\;   dydx=1  \;\displaystyle \frac{{\rm d}y}{{\rm d}x} = -1\; and   y=0  \;y=0\;.

    We substitute the first condition into dydx=1x+A\displaystyle \frac{{\rm d}y}{{\rm d}x} = -{1\over x+A} to obtain   A=1  \;A=1\;.

    Then substitute AA and the second condition into the eventual solution to find   B=0\;B=0.


Alternatively, if we instead know that:

  •   y(0)=0  \;y(0)=0\; and   y(e1)=1\;y(e-1)=-1.

    This time both conditions can be substituted into the solution:

    y(0)=00=Bln(A)B=ln(A)\displaystyle y(0)=0 \Rightarrow 0=B-\ln(A) \Rightarrow B=\ln(A) > y(e1)=11=ln(A)lne1+AA=1\displaystyle y(e-1)=-1 \Rightarrow -1=\ln(A)-\ln{e-1+A} \Rightarrow A=1

More integration tricks

Let us return to, and solve, our leaf example:

dydt=k1yk2y2=y(k1k2y)\displaystyle {{\rm d}y\over {\rm d}t}=k_1y-k_2y^2=y(k_1-k_2y)

This is a separable differential equation:

dyy(k1k2y)=dt.  \displaystyle \int {{\rm d}y\over y(k_1-k_2y)} =\int {\rm d}t.\;

We can split apart the integral on the RHS using partial fractions in SymPy using sp.apart.

We want 1y(k1k2y)=Ay+B(k1k2y)\displaystyle \qquad{1\over y(k_1-k_2y)}={A\over y}+{B\over (k_1-k_2y)}:

import sympy as sp y, k1, k2 = sp.symbols('y k_1 k_2') sp.apart(1 / (y*(k1 - k2*y)),y)

k2k1(k1+k2y)+1k1y\displaystyle - \frac{k_{2}}{k_{1} \left(- k_{1} + k_{2} y\right)} + \frac{1}{k_{1} y}

So A=1k1\displaystyle A={1\over k_1} and B=k2k1B={k_2\over k_1}.

 Thus,    dyy(k1k2y)=dyk1y+k2k1(k1k2y)dy=dt\displaystyle {\rm~Thus,~~~~}\int {{\rm d}y\over y(k_1-k_2y)}=\int {{\rm d}y\over k_1y}+\int {k_2\over k_1(k_1-k_2y)}{\rm d}y =\int dt

 Thus      1k1lnyk2k1k2ln(k1k2y)=t+c\displaystyle {\rm~Thus~~~~~~ }{1\over k_1}\ln y-{k_2\over k_1k_2}\ln(k_1-k_2y)=t + c

We can get cc from initial conditions. Try doing the algebraic manipulation of this to make yy the subject of the equation:

y=k1exp(k1t+d)1+k2exp(k1t+d)\displaystyle y={k_1\exp (k_1t+d)\over 1+ k_2 \exp(k_1t + d)}

where dd is a constant.

Introductory problems

Introductory problems 1

Find the general solutions of the following differential equations:

  1. dydx=x2+ex\displaystyle \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} \dd{y}{x} = x^2 + e^x

  2. dydx=y2x\displaystyle \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} \dd{y}{x} = \frac{y^2}{x}

  3. 1xdydx=e4x\displaystyle \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} \frac{1}{x}\dd{y}{x} = e^{4x}

  4. dydx=2xy\displaystyle \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} \dd{y}{x} = -2xy

Check your answers by differentiating them.

Main problems

Main problems 1

A circular patch of oil on the surface of some water has a radius rr metres at time tt minutes. When t=0t=0 minutes, r=1r=1\,m and when t=10t=10 minutes, r=2r=2\,m.

  1. Predict the value TT of tt when r=4r=4\,m, using a simple model in which the rate of increase of rr is taken to be constant. Find TT for this model.

  2. In a more refined model, the rate of increase of rr is taken to be proportional to 1/r1/r. Express this statement as a differential equation, and find the general solution. Find TT for this model.

  3. Compare the two models used in 1. and 2., by sketching r(t)r(t) on the same figure or plotting using Python. Comment on the differences seen during different time intervals.

Main problems 2

A nuclear installation local to Oxford 'lost' 17g of Cobalt-60 between two inspections 6 months apart. A spokesperson told a newspaper reporter that the loss was due to 'natural radioactive decay' during that period.

If this explanation was correct, what mass of Cobalt was stored on the site? (The half life of 60^{60}Co = 5.265.26 years.)

Main problems 3

By making a substitution z=dydx\displaystyle \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} z = \dd{y}{x}, solve the equation

d2ydx2=(13x2)(dydx)2withy(2)=0andy(2)=1/6.\displaystyle \def\d#1{{\rm d}#1} \def\ddd#1#2{{{{\rm d}^2#1}\over{\d{#2}^2}}} \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} \ddd{y}{x} = (1-3x^2)\left(\dd{y}{x}\right)^2\quad{\rm with}\quad y(2) = 0\quad{\rm and}\quad y'(2) = 1/6.

Hint: you will need to use partial fractions for part of this question, to break up

1x3x=1x+1/2x+1+1/2x1.\displaystyle\frac{1}{x^3-x} = \frac{-1}{x} + \frac{1/2}{x+1} + \frac{1/2}{x-1}.

Main problems 4

Suppose a cell contains a chemical (the solute) dissolved in it at a concentration of c(t)\displaystyle c(t), and the concentration of the same substance outside the cell is a constant kk. By Fick's law, if c(t)\displaystyle c(t) and kk are unequal, solute moves across the cell wall at a rate proportional to the difference between c(t)\displaystyle c(t) and kk, towards the region of lower concentration.

  1. Write down a differential equation which is satisfied by c(t)\displaystyle c(t).

  2. Solve this differential equation with the initial condition c(0)=c0\displaystyle c(0)=c_0.

  3. Sketch the solutions for c0>k\displaystyle c_0 > k and k>c0\displaystyle k > c_0.

  4. Blood glucose concentration is 5.1 mM and the concentration inside the cell is at 0.1 mM. If glucose utilisation within the cell is totally inhibited, it takes 1 min for the intracellular concentration to reach 2.6 mM. How long would it take for the concentration to reach 5.0 mM?

  5. Calculate the amount of glucose (moles) entering the cell to bring the concentration from 0.1 mM to 5 mM assuming the cell is spherical with a diameter of 10μ10\,\mum.

Extension problems

Extension problems 1

Consider a simple model of the production and degradation of a protein, shown by the reaction chain

k1Sk2\displaystyle \stackrel{k_1}{\longrightarrow} S \stackrel{k_2}{\longrightarrow}

where k1k_1 and k2k_2 are mass action coefficients.

  1. Form and solve a differential equation describing the change in protein concentration.

  2. What concentration is reached after 'sufficient' time has elapsed?