Differential Equations

Introduction

Differential equations promote the understanding and modeling of a multitude of phenomena in the natural world. These include the growth of populations, the behavior of subatomic particles, or thermal conduction, just to name a few examples. They provide a powerful mathematical framework for describing change and dynamics in diverse fields such as physics, engineering, biology, economics, and more. In this chapter we focus on two fundamental categories: ordinary differential equations (ODEs) and partial differential equations (PDEs).

Differential equations are mathematical expressions that describe how a function changes with respect to one or more independent variables. ODEs deal with functions of a single variable, encapsulating phenomena that evolve in one dimension, while PDEs are concerned with functions of multiple variables, allowing us to investigate systems that evolve, usually over time, in two or more dimensions. Together, ODEs and PDEs are indispensable tools for understanding and predicting the behavior of dynamic systems.

Definitions and Terminology

The derivative dy/dx\mathrm{d} y / \mathrm{d} x of a function y(x)y(x) is itself another function y(x)y'(x) found by an appropriate rule. Consider the exponential function y(x)=e0.1x2y(x) = \mathrm{e}^{0.1x^2} for example. It is differentiable on the interval (,)(-\infty, \infty) and by the chain rule its first derivative is given by dy(x)/dx=0.2xe0.1x2\mathrm{d} y(x) / \mathrm{d} x = 0.2x\mathrm{e}^{0.1x^2}. If we plug in y=y(x)y=y(x) on the right-hand side of this equation we get

dydx=0.2xy . \frac{\mathrm{d} y}{\mathrm{d} x} = 0.2 x y\,.

Now imagine that you are handed equation (1) and have no prior knowledge about yy. Then the problem at hand can be formulated like this.

How do you solve an equation such as (1) for the function y(x)y(x)?

Equation (1) is called a differential equation. In general, any equation containing the derivatives of one or more unknown functions or dependent variables, with respect to one or more independent variables, is said to be a differential equation (DE).

Throughout this text ordinary derivatives will be written by using either the Leibniz notation dy/dx\mathrm{d} y / \mathrm{d} x or the prime notation yy'. Using the latter DEs can be written a little more compactly. In physical sciences and engineering, Newton's dot notation y˙\dot y is also used to denote derivatives with respect to time. Partial derivatives are often denoted by a subscript notation uxu_x indicating the independent variable xx.

Classification

DEs can be classified according to type, order, and linearity.

Type: If a differential equation contains only ordinary derivatives of one or more unknown functions with respect to a single independent variable, it is said to be an ordinary differential equation (ODE). An equation involving partial derivatives of one or more unknown functions of two or more independent variables is called a partial differential equation (PDE).

Order: The order of either an ODE or a PDE is the order of the highest derivative in the equation. In symbols we can express an nn-th-order ODE in one dependent variable by the general form

F(x,y,y,,y(n))=0 , F(x,y,y',\ldots,y^{(n)}) = 0\,,

where FF is a real-valued function of n+2n+2 variables. Note, that without loss of generality to higher-order systems, we can restrict ourselves to first-order DEs. That is because any higher-order ODE can be inflated into a larger system of first-order equations by introducing new variables. For example, the second-order equation y=yy'' = -y can be rewritten as a system of two first-order equations

y=z ,z=y . \begin{aligned} y' &= z\,, \\ z' &= -y\,. \end{aligned}

Linearity: An nn-th-order ODE (2) is said to be linear if FF is linear in y,y,,y(n)y,y',\ldots,y^{(n)}. A nonlinear ordinary differential equation is simply one that is not linear. Nonlinear functions of the dependent variable or its derivatives, such as siny\sin y or ey\mathrm{e}^{y'}, cannot appear in a linear equation.

Solutions of an ODE

Any function ϕ\phi, defined on an interval II and possessing at least nn derivatives that are continuous on II, which when substituted into an nn-th-order ODE reduces the equation to an identity, is said to be a solution of the equation on the interval. In other words, a solution of an nn-th-order ODE (2) is a function ϕ\phi that possesses at least nn derivatives and for which

xI ⁣:F(x,ϕ(x),ϕ(x),,ϕ(n)(x))=0 . \forall x \in I\colon F\big(x,\phi(x),\phi'(x), \ldots, \phi^{(n)}(x) \big) = 0\,.

We say that ϕ\phi satisfies the differential equation on II. For our purposes we shall also assume that a solution ϕ\phi is a real-valued function.

When solving a first-order differential equation F(x,y,y)F(x, y, y') we usually obtain a solution containing a single constant or parameter cc. A solution of F(x,y,y)F(x, y, y') containing a constant cc is a set of solutions called a one-parameter family of solutions. When solving an nn-th-order differential equation F(x,y,y,,y(n))F(x, y, y', \ldots, y^{(n)}) we seek an nn-parameter family of solutions. This means that a single differential equation can possess an infinite number of solutions corresponding to an unlimited number of choices for the parameter(s). A solution of a differential equation that is free of parameters is called a particular solution.

Systems of DEs

Often in theory, as well as in many applications, we deal with systems of DEs. A system of ODEs is two or more equations involving the derivatives of two or more unknown functions of a single independent variable. For example, if xx and yy denote dependent variables and tt denotes the independent variable, then a system of two first-order differential equations is given by

dxdt=f(t,x,y) ,dydt=g(t,x,y) . \begin{aligned} \frac{\mathrm{d} x}{\mathrm{d} t} &= f(t, x, y)\,,\\ \frac{\mathrm{d} y}{\mathrm{d} t} &= g(t, x, y)\,. \end{aligned}

A solution of such a system is a pair of differentiable functions x=ϕ1(t),y=ϕ2(t)x = \phi_1(t), y = \phi_2(t), defined on a common interval II, that satisfy each equation of the system on this interval.

Initial-Value Problems

We are often interested in problems in which we seek a solution y(x)y(x) of a DE so that y(x)y(x) also satisfies certain prescribed side conditions, that is, conditions that are imposed on the unknown function y(x)y(x) and its derivatives at a number x0x_0. On some interval II containing x0x_0 the problem of solving an nn-th-order DE subject to nn side conditions specified at x0x_0

Solvednydxn=f(x,y,y,,y(n1))Subject toy(x0)=y0,y(x0)=y1,,y(n1)(x0)=yn1 \begin{aligned} \text{Solve}& \quad \frac{\mathrm{d}^n y}{\mathrm{d} x^n} = f(x,y,y',\ldots,y^{(n-1)}) \\ \text{Subject to}& \quad y(x_0) = y_0, y'(x_0) = y_1, \ldots, y^{(n-1)}(x_0) = y_{n-1} \end{aligned}

where y0,y1,,yn1y_0,y_1, \ldots, y_{n-1} are arbitrary constants, is called an nn-th-order initial-value problem (IVP). The values of y(x)y(x) and its first n1n-1 derivatives at x0,y(x0)=y0,y(x0)=y1,,y(n1)(x0)=yn1x_0, y(x_0)=y_0, y'(x_0)=y_1, \ldots, y^{(n-1)}(x_0) = y_{n-1} are called initial conditions (ICs). Solving an nn-th-order IVP frequently entails first finding an nn-parameter family of solutions of the DE and then using the ICs at x0x_0 to determine the nn constants in this family. The resulting particular solution is defined on some interval II containing the number x0x_0.

Geometric Interpretation

Consider the second-order IVP

d2ydx2=f(x,y,y) ,y(x0)=y0,y(x0)=y1 . \begin{aligned} \frac{\mathrm{d}^2 y}{\mathrm{d} x^2} &= f(x,y,y')\,, \\ y(x_0) &= y_0, y'(x_0) = y_1\,. \end{aligned}

We want to find a solution y(x)y(x) of the DE yf(x,y,y)y'' - f(x,y,y') on an interval II containing x0x_0 such that its graph not only passes through (x0,y0)(x_0,y_0) bu the slope of the curve at this point is the number y1y_1. A solution curve is shown in blue in the following Figure.

 All solutions (shaded area) and several particular solutions (colored) of the DE on an interval.
Figure All solutions (shaded area) and several particular solutions (colored) of the DE on an interval.

The words initial conditions derive from physical systems where the independent variable is time tt and where y(t0)y0y(t_0) - y_0 and y(t0)y1y'(t_0)-y_1 represent the position and velocity, respectively, of an object at some beginning, or initial, time t0t_0.

Example: Falling Bodies

To construct a mathematical model of the motion of a body moving in a force field, one often starts with the laws of motion formulated by the English mathematician Isaac Newton. Recall from elementary physics that Newton’s first law of motion states that a body either will remain at rest or will continue to move with a constant velocity unless acted on by an external force. In each case this is equivalent to saying that when the sum of the forces F=FkF = \sum F_k, the so-called net or resultant force, acting on the body is zero, then the acceleration aa of the body is zero. Newton's second law of motion indicates that when the net force acting on a body is not zero, then the net force is proportional to its acceleration aa or, more precisely, F=maF = ma, where mm is the mass of the body.

Now suppose a baseball is tossed upward from the roof of a tall building. What is the position s(t)s(t) of the baseball relative to the ground at time tt? The acceleration of the baseball is the second derivative d2s/dt2\mathrm{d}^2 s / \mathrm{d} t^2. If we assume that the upward direction is positive and that no force acts on the baseball other than the force of gravity, then Newton’s second law gives

md2sdt2=mgord2sdt2=g . m\frac{\mathrm{d}^2 s}{\mathrm{d} t^2} = -mg \quad\text{or}\quad \frac{\mathrm{d}^2 s}{\mathrm{d} t^2} = -g\,.

In other words, the net force is simply the weight F=F1=WF = F_1 = −W of the baseball near the surface of the Earth. Recall that the magnitude of the weight is W=mgW = mg, where mm is the mass of the body and gg is the acceleration due to gravity. The minus sign is used because the weight of the baseball is a force directed downward, which is opposite to the positive direction. If the height of the building is s0s_0 and the initial velocity of the baseball is v0v_0, then ss is determined from the second-order IVP

d2sdt2=g ,s(0)=s0 ,s(0)=v0 . \frac{\mathrm{d}^2 s}{\mathrm{d} t^2} = -g\,,\quad s(0) = s_0\,,\quad s'(0) = v_0\,.

This can easily be solved by integrating the constant g−g twice with respect to tt. The ICs determine the two constants of integration which yields

s(t)=12gt2+v0t+s0 . s(t) = -\frac{1}{2} gt^2 + v_0t + s_0\,.

Using Julia we can formulate this problem and solve it numerically.

using OrdinaryDiffEq, PlotlyJS

# parameters
g = 9.81  # earth's gravity

# initial conditions
s₀ = [55.86]  # Leaning Tower of Pisa [m]
ds₀ = [20.0]  # average baseball throw [m/s]
tspan = (0.0, 7.0)  # time [s]

# define the problem
fallingbody!(dds, ds, s, p, t) = @. dds = -g

# pass to solvers
prob = SecondOrderODEProblem(fallingbody!, ds₀, s₀, tspan)
sol = solve(prob, DPRKN6(); saveat=0.5)

# define analytical solution
trueposition(t) = @. -1/2*g*t^2 + ds₀*t + s₀

# plot results
layout = Layout(;
    xaxis_title="Time [s]",
    yaxis_title="Position [m]",
)
trace1 = scatter(x=sol.t, y=max.(0, trueposition(sol.t)), name="true", mode="lines")
trace2 = scatter(x=sol.t, y=max.(0, last.(sol.u)), name="numerical")
plt = plot([trace1, trace2], layout)

In the model given in (3) the resistive force of air was ignored. Under some circumstances a falling body of mass mm, such as a feather with low density and irregular shape, encounters air resistance proportional to its instantaneous velocity vv. If we take the positive direction to be oriented upward, then the net force acting on the mass is given by F=F1+F2=mg+kvF = F_1 + F_2 = -mg + kv, where the weight F1=mgF_1 = -mg of the body is force acting in the negative direction and air resistance F2=kvF_2 = kv is a force, called viscous damping, acting in the opposite or upward direction. Now, since vv is related to acceleration aa by a=dv/dta = \mathrm{d} v / \mathrm{d} t, Newton’s second law becomes F=ma=mdv/dtF = ma = m \mathrm{d} v / \mathrm{d} t. By equating the net force to this form of Newton’s second law, we obtain a first-order DE for the velocity v(t)v(t) of the body at time tt

mdvdt=mg+kv . m\frac{\mathrm{d} v}{\mathrm{d} t} = -mg + kv\,.

Here kk is a positive constant of proportionality. If s(t)s(t) is the distance the body falls in time tt from its initial point of release, then v=ds/dtv=\mathrm{d} s / \mathrm{d} t and a=dv/dt=d2s/dt2a = \mathrm{d} v / \mathrm{d} t = \mathrm{d}^2 s / \mathrm{d} t^2. In terms of ss this yields a second-order DE

md2sdt2=mg+kdsdtormd2sdt2+kdsdt=mg . m \frac{\mathrm{d}^2 s}{\mathrm{d} t^2} = -mg + k \frac{\mathrm{d} s}{\mathrm{d} t} \quad\text{or}\quad m\frac{\mathrm{d}^2 s}{\mathrm{d} t^2} + k \frac{\mathrm{d} s}{\mathrm{d} t} = -mg\,.

We can adapt the Julia code snippet above to also account for the viscous damping factor.

using OrdinaryDiffEq, PlotlyJS

# parameters of Apollo 15 experiment
g = 9.81  # earth's gravity
k = 1.0
m_feather = 0.03  # [kg]
m_hammer = 1.32  # [kg]

# initial conditions
s₀ = [55.86]  # Leaning Tower of Pisa [m]
ds₀ = [0.0]  # drop [m/s]
tspan = (0, 15)  # [s]

# define the problems
function fallingbodyair!(dds, ds, s, p, t)
    k, m = p

    return @. dds = -m*g + k*ds
end

# pass to solvers
prob = SecondOrderODEProblem(fallingbodyair!, ds₀, s₀, tspan, [k, m_feather])
sol_feather = solve(prob, DPRKN6(); saveat=0.1)
prob = SecondOrderODEProblem(fallingbodyair!, ds₀, s₀, tspan, [k, m_hammer])
sol_hammer = solve(prob, DPRKN6(); saveat=0.1)

# plot results
layout = Layout(;
    xaxis_title="Time [s]",
    yaxis_title="Position [m]",
)

trace1 = scatter(x=sol_feather.t, y=max.(0, last.(sol_feather.u)), name="feather")
trace2 = scatter(x=sol_hammer.t, y=max.(0, last.(sol_hammer.u)), name="hammer")

plt = plot([trace1, trace2], layout)

Direction Fields

Let us assume that for some first-order DE dy/dx=f(x,y)\mathrm{d} y / \mathrm{d} x = f(x, y) we can neither find a solution nor invent a method for solving it analytically. This is not as bad a predicament as one might think, since the DE itself can be used to investigate how its solutions “behave”. Even if an analytical or numerical solution has been found this qualitative analysis can be used to confirm the results. Direction fields tell us, in an approximate sense, what a solution curve must look like without actually solving the equation.

If we systematically evaluate ff over a rectangular grid of points in the xyxy-plane and draw a line element at each point (x,y)(x, y) of the grid with slope f(x,y)f(x, y) like the vector

[1,f(x,y)] , [1, f(x,y)]^\intercal\,,

then the collection of all these line elements is called a direction field or a slope field of the DE. Visually, the direction field suggests the appearance or shape of a family of solution curves of the DE, and consequently, it may be possible to see at a glance certain qualitative aspects of the solutions, e.g., regions in the plane, in which a solution exhibits an unusual behavior. A single solution curve that passes through a direction field must follow the flow pattern of the field. It is tangent to a lineal element when it intersects a point in the grid. The Figure below shows a direction field of the DE dy/dx=0.2xy\mathrm{d} y / \mathrm{d} x = 0.2xy over a region of the xyxy-plane.

using Plots
gr()

xs, ys, us, vs = [], [], [], []
f(x, y) = 0.2*x*y

space = -5:1.0:5

for x in space, y in space
    push!(xs, x), push!(ys, y)

    v = f(x, y)
    norm = (1 + v^2)^(1/2)

    push!(us, 1 / norm), push!(vs, v / norm)
end

quiver(xs, ys, quiver=(us, vs))

Systems of DEs

We have seen that a single DE can serve as a mathematical model for a single population in an environment. But if there are, say, two interacting and perhaps competing species living in the same environment (for example, rabbits and foxes), then a model for their populations x(t)x(t) and y(t)y(t) might be a system of two first-order DE such as

dxdt=g1(t,x,y) ,dydt=g2(t,x,y) . \begin{aligned} \frac{\mathrm{d} x}{\mathrm{d} t} &= g_1(t, x, y)\,, \\ \frac{\mathrm{d} y}{\mathrm{d} t} &= g_2(t, x, y)\,. \end{aligned}

When g1g_1 and g2g_2 are linear in the variables xx and yy then (4) is said to be a linear system.

General Definition

Let ΩR×(Rm)n+1\Omega \subset \mathbb R \times (\mathbb R^m)^{n+1}, nNn\in\mathbb N, and f ⁣:ΩRmf\colon \Omega \to \mathbb R^m continuous. Then

f(x,y,y,y,,y(n1))=0 f(x,y,y',y'', \ldots, y^{(n-1)}) = 0

is called an explicit system of ordinary differential equations of order nn. The implicit analogue is given by

f(x,y,y,y,,y(n))=0 . f(x,y,y',y'', \ldots, y^{(n)}) = 0\,.

Example: Lotka-Volterra Model

Suppose two different species of animals interact within the same environment or ecosystem. Suppose further that the first species eats only vegetation and the second eats only the first species. In other words, one species is the predator, and the other is prey. For example, wolves hunt grass-eating caribou, sharks devour little fish, and the snowy owl pursues an arctic rodent called the lemming. For the sake of discussion, let us imagine that the predators are foxes and the prey are rabbits. Let x(t)x(t) and y(t)y(t) denote the fox and rabbit populations, respectively, at time tt. If there were no rabbits, then one might expect that the foxes, lacking an adequate food supply, would decline in number according to

dxdt=ax ,x>0 . \frac{\mathrm{d} x}{\mathrm{d} t} = -ax\,,\quad x > 0\,.

When rabbits are present in the environment, however, it seems reasonable that the number of encounters or interactions between these two species per unit time is jointly proportional to their populations xx and yy., i.e., proportional to the product xyxy. Thus, when rabbits are present, there is a supply of food, so foxes are added to the system at a rate bxybxy, b>0b>0. Adding this last rate to (5) gives a model of the fox population

dxdt=ax+bxy . \frac{\mathrm{d} x}{\mathrm{d} t} = -ax + bxy\,.

On the other hand, if there were no foxes, then the rabbits would, with an added assumption of unlimited food supply, grow at a rate that is proportional to the number of rabbits present at time tt

dydt=dy ,d>0 . \frac{\mathrm{d} y}{\mathrm{d} t} = dy\,,\quad d>0\,.

But when foxes are present, a model for the rabbit population is this equation decreased by cxycxy, c>0c>0, that is, decreased by the rate at which the rabbits are eaten during their encounters with the foxes

dydt=dycxy . \frac{\mathrm{d} y}{\mathrm{d} t} = dy - cxy\,.

This constitutes the system of nonlinear DEs

dxdt=ax+bxy=x(a+by) ,dydt=dy+cxy=y(dcx) , \begin{aligned} \frac{\mathrm{d} x}{\mathrm{d} t} &= -ax + bxy = x(-a + by)\,,\\ \frac{\mathrm{d} y}{\mathrm{d} t} &= dy + cxy = y(d - cx)\,,\\ \end{aligned}

where a,b,ca,b,c, and dd are positive constants. This famous system of equations is known as the Lotka-Volterra predator-prey model.

using OrdinaryDiffEq, PlotlyJS

function lotka_volterra(du, u, params, t)
    🐰, 🐺 = u
    α, β, δ, γ = params
    du[1] = d🐰 = α*🐰 - β*🐰*🐺
    du[2] = d🐺 = -δ*🐺 + γ*🐰*🐺
end

u0 = [1.0, 1.0]
tspan = (0.0, 15.0)
params = [1.5, 1.0, 3.0, 1.0]

prob = ODEProblem(lotka_volterra, u0, tspan, params)
sol = solve(prob, Tsit5(); saveat=0.2)

# plot results
layout = Layout(;
    xaxis_title="Time [d]",
    yaxis_title="Number",
)

rabbits = scatter(x=sol.t, y=first.(sol.u), name="rabbits")
wolves = scatter(x=sol.t, y=last.(sol.u), name="wolves")

plt = plot([rabbits, wolves], layout)

Exercise

Model the spread of a contagious disease using the compartmental SIR model from epidemiology. See also notebooks/contagious_disease.jl.

Partial Differential Equations

An ODE describes the relation between an unknown function depending on a single variable and its derivatives. A partial differential equation (PDE) describes a relation between an unknown function and its partial derivatives. PDEs appear frequently in all areas of physics and engineering. Moreover, in recent years we have seen a dramatic increase in the use of PDEs in areas such as biology, chemistry, computer sciences (particularly in relation to image processing and graphics) and in economics (finance). In fact, in each area where there is an interaction between a number of independent variables, we attempt to define functions in these variables and to model a variety of processes by constructing equations for these functions. When the value of the unknown function(s) at a certain point depends only on what happens in the vicinity of this point, we shall, in general, obtain a PDE. The general form of a PDE for a function u(x1,x2,,xn)u(x_1, x_2, \ldots, x_n) is given by

F(x1,x2,,xn,u,ux1,ux2,,ux11,)=0 , F(x_1, x_2, \ldots, x_n, u, u_{x_1}, u_{x_2}, \ldots, u_{x_{11}}, \ldots) = 0\,,

where x1,x2,,xnx_1, x_2, \ldots, x_n are the independent variables, uu is the unknown function, and uxju_{x_j} denotes the partial derivative u/xj\partial u / \partial x_j. Also partial derivatives of higher order like u/xjk\partial u / \partial x_{jk} are possible. The equation is, in general, supplemented by additional conditions such as initial conditions, as we have already seen in the theory of ODEs, or boundary conditions.

Classification

Similar to ODEs we can classify PDEs into different categories.

Order: The order is defined to be the order of the highest derivative in the equation. If the highest derivative is of order kk, then the PDE is said to be of order kk. Thus, for example, the equation uttuxx=f(x,t)u_{tt} - u_{xx} = f(x,t) is called a second-order equation, while ut+uxxx=0u_t + u_{xxx} = 0 is called a third-order equation.

Linearity: A PDE is called linear if in (6), FF is a linear function of the unknown function uu and all of its derivatives. For example, x7ux+exyuy+sin(x2+y2)u=x3x^7u_x + \mathrm{e}^{xy}u_y + \sin(x^2 + y^2)u= x^3 is a linear equation while ux2+uy2=1u_x^2 + u_y^2=1 is a nonlinear equation.

Scalar versus system: A single PDE with just one unknown function is called a scalar equation. In contrast, a set of mm equations with \ell unknown functions is called a system of mm equations.

Example: Poisson's Equation

Poisson's equation is a second-order PDE frequently used in theoretical physics. Given the Laplace operator in nn-dimensional space

Δ=j=1n2xj2 \Delta = \sum_{j=1}^n \frac{\partial^2}{\partial x_j^2}

it is defined by

Δϕ=f , \Delta \phi = f\,,

where the initial condition ff is given and ϕ\phi is the unknown solution.

References

  • Dennis G. Zill, A First Course in Differential Equations with Modeling Applications, 2018.

  • Simon Frost, SIR model in Julia using DifferentialEquations, 2018, http://epirecip.es/epicookbook/chapters/sir/julia.

  • Pinchover and Rubinstein, An Introduction to Partial Differential Equations, 2005.

CC BY-SA 4.0 Johannes Sappl. Last modified: November 11, 2023. Website built with Franklin.jl and the Julia programming language.