Lecture 12: Derivatives and differential equations#

Recap#

  • We discussed the concept of rate of change

    • speed is the rate of change of distance;

    • instantaneous speed is the limit of average speeds over shorter and shorter time periods,

      D(t+dt)D(t)dt as dt0;
    • instantaneous rate of change as the limit of

      (value at time t+dt)(value at time t)dt as dt0.
  • We defined the derivative of a function y(t) by

    y(t)=limdt0y(t+dt)y(t)dt.
  • We saw that speed, S(t), is the derivative of distance covered, D(t):

    S(t)=D(t)=limdt0D(t+dt)D(t)dt.
  • We saw a geometric interpretation of the derivative of y(t) by considering the slope of its graph:

../_images/b0ad9db9f9f8ff9d45c36c4d40a640e2bc3ffd73c74cd07afbbeeee1684da3c4.png
  • The slope of the straight line approximation (chord) is

    y(t+dt)y(t)dt.

Graphs and derivatives#

  • We now know a geometric interpretation of the derivative of a function, as being equal to the function’s slope at each point.

  • This means we can sketch an approximation to the derivative of any given function.

  • In the following examples, the graph of a function y(t) is given and the graph of y(t) is then approximated.

Example 1#

../_images/d4423f217066c8fe3b9c72f81a873bb4f3b527d760fc9d397db606f80057a4b2.png

Example 2#

../_images/40b3b1dd60c1c2aaf197dbd7c64e6226e628e241f486ba97c8a0997ec341e47d.png

Example 3#

The population of Leeds over time (fitted):

../_images/4ebc300e2c017251c76a90dd255b7e03145854fa8629dcd359a7a69d4b1b5cc5.png

Differential equations#

  • We have already seen that, for speed, S(t)=D(t).

  • What is the rate of change of speed?

  • Answer: acceleration, a(t) say:

    • a positive value for a(t) means that speed is increasing whilst a negative value means that speed is decreasing.

  • When a model takes the form of an equation which involves one or more derivatives then it is called a differential equation.

  • We have already seen (and computationally solved) a simple example of a differential equation:

    D(t)=1+5t6t2

    where D(0)=0.

  • Most models of dynamic processes take the form of differential equations.

  • The following example uses the fact that the acceleration of an object is equal to the rate of change of its speed:

    • i.e. a(t)=S(t).

An object in free fall#

  • Consider a simple model for an object falling from a large height, based on the two following assumptions:

    1. all objects are attracted downward with an acceleration due to gravity of 9.81m/s2;

    2. air resistance causes an object to decelerate in proportion to its speed (i.e., the faster it travels the greater the air resistance).

  • What is the net acceleration on the object?

    • If it is falling with speed S(t) the net acceleration downwards is gkS(t) for some constant k.

  • This results in the following differential equation:

    S(t)=gkS(t).
  • How could we solve this equation?

    • Recall how we solved D(t)=1+5t6t2?

    • We can do a similar thing again: divide the time period into lots of small intervals and assume everything is approximately constant on each time interval.

  • We know that

    S(t)=limdt0S(t+dt)S(t)dtS(t+dt)S(t)dt

    for a small value of dt.

  • Hence we can say that:

    S(t+dt)=S(t)+dt(gkS(t)).

Python algorithm:#

def freefall(n):
    """
    Plot the trajectory of an object falling freely.
    Input: n number of timesteps
    """

    tfinal = 50.0  # Select the final time
    g = 9.81  # acceleration due to gravity (m/s)
    k = 0.2  # air resistance coefficient

    # initialise time and speed arrays array
    t = np.zeros([n + 1, 1])
    s = np.zeros([n + 1, 1])

    # set initial conditions
    s[0] = 0.0
    t[0] = 0.0

    dt = (tfinal - t[0]) / n  # calculate step size

    # take n time steps, in which it is assumed that the acceleration
    # is constant in each small time interval
    for i in range(n):
        t[i + 1] = t[i] + dt
        s[i + 1] = s[i] + dt * (g - k * s[i])

    # plot output
    plt.plot(t, s, label=f"n = {n}")

Python algorithm: Results#

../_images/35fd6fe5634bc9e0f86aca0cf1889b4d5e879c11eba8525cf5551e54b93525e0.png

Euler’s method#

  • The approach we have used applies for any differential equation involving just a single derivative.

  • It is called Euler’s method.

  • We can always arrange such an equation in the form:

    y(t)=f(t,y) subject to the initial condition y(t0)=y0.
  • Examples:

    1. y(t)=1+5t6t2 and y(0)=0.

    2. y(t)=gky and y(0)=0.

    3. y(t)=y2+1t and y(1)=2.

For the general equation we have the following algorithm:

  1. Set initial values t(0) and y(0).

  2. Loop over all time steps, until the final time, updating using the formulae:

    y(i+1)=y(i)+dtf(t(i),y(i))t(i+1)=t(i)+dt.

Example#

  • Take three steps of Euler’s method to approximate the solution of

    y(t)=y2+1t subject to the initial condition y(1)=2

    for 1t2.

  • For this example we have:

    • n=3

    • t0=1

    • y0=2

    • tfinal=2

    • dt=(21)/3=1/3

    • f(t,y)=y2+1/t.

Summary#

  • Given the graph of y(t) it is possible to sketch the graph of y(t) (with some care!).

  • Computational models which involve dynamic processes usually involve the use of derivatives.

  • An equation which includes a derivative is known as a differential equation.

  • To solve a differential equation it is necessary to know some information about the solution at some starting point (e.g. initial distance travelled, initial speed, population at a given point in time, etc.).

  • One computational approach to solve such equations is Euler’s method - which gets more accurate with more sub-intervals used.

Further reading#

Euler’s method in films:

The slides used in the lecture are also available