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.
The derivative of a function is itself another function found by an appropriate rule. Consider the exponential function for example. It is differentiable on the interval and by the chain rule its first derivative is given by . If we plug in on the right-hand side of this equation we get
Now imagine that you are handed equation (1) and have no prior knowledge about . Then the problem at hand can be formulated like this.
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 or the prime notation . Using the latter DEs can be written a little more compactly. In physical sciences and engineering, Newton's dot notation is also used to denote derivatives with respect to time. Partial derivatives are often denoted by a subscript notation indicating the independent variable .
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 -th-order ODE in one dependent variable by the general form
where is a real-valued function of 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 can be rewritten as a system of two first-order equations
Linearity: An -th-order ODE (2) is said to be linear if is linear in . A nonlinear ordinary differential equation is simply one that is not linear. Nonlinear functions of the dependent variable or its derivatives, such as or , cannot appear in a linear equation.
Any function , defined on an interval and possessing at least derivatives that are continuous on , which when substituted into an -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 -th-order ODE (2) is a function that possesses at least derivatives and for which
We say that satisfies the differential equation on . For our purposes we shall also assume that a solution is a real-valued function.
When solving a first-order differential equation we usually obtain a solution containing a single constant or parameter . A solution of containing a constant is a set of solutions called a one-parameter family of solutions. When solving an -th-order differential equation we seek an -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.
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 and denote dependent variables and denotes the independent variable, then a system of two first-order differential equations is given by
A solution of such a system is a pair of differentiable functions , defined on a common interval , that satisfy each equation of the system on this interval.
We are often interested in problems in which we seek a solution of a DE so that also satisfies certain prescribed side conditions, that is, conditions that are imposed on the unknown function and its derivatives at a number . On some interval containing the problem of solving an -th-order DE subject to side conditions specified at
where are arbitrary constants, is called an -th-order initial-value problem (IVP). The values of and its first derivatives at are called initial conditions (ICs). Solving an -th-order IVP frequently entails first finding an -parameter family of solutions of the DE and then using the ICs at to determine the constants in this family. The resulting particular solution is defined on some interval containing the number .
Consider the second-order IVP
We want to find a solution of the DE on an interval containing such that its graph not only passes through bu the slope of the curve at this point is the number . A solution curve is shown in blue in the following Figure.
The words initial conditions derive from physical systems where the independent variable is time and where and represent the position and velocity, respectively, of an object at some beginning, or initial, time .
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 , the so-called net or resultant force, acting on the body is zero, then the acceleration 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 or, more precisely, , where is the mass of the body.
Now suppose a baseball is tossed upward from the roof of a tall building. What is the position of the baseball relative to the ground at time ? The acceleration of the baseball is the second derivative . 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
In other words, the net force is simply the weight of the baseball near the surface of the Earth. Recall that the magnitude of the weight is , where is the mass of the body and 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 and the initial velocity of the baseball is , then is determined from the second-order IVP
This can easily be solved by integrating the constant twice with respect to . The ICs determine the two constants of integration which yields
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 , such as a feather with low density and irregular shape, encounters air resistance proportional to its instantaneous velocity . If we take the positive direction to be oriented upward, then the net force acting on the mass is given by , where the weight of the body is force acting in the negative direction and air resistance is a force, called viscous damping, acting in the opposite or upward direction. Now, since is related to acceleration by , Newton’s second law becomes . By equating the net force to this form of Newton’s second law, we obtain a first-order DE for the velocity of the body at time
Here is a positive constant of proportionality. If is the distance the body falls in time from its initial point of release, then and . In terms of this yields a second-order DE
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) Let us assume that for some first-order DE 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 over a rectangular grid of points in the -plane and draw a line element at each point of the grid with slope like the vector
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 over a region of the -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))
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 and might be a system of two first-order DE such as
When and are linear in the variables and then (4) is said to be a linear system.
Let , , and continuous. Then
is called an explicit system of ordinary differential equations of order . The implicit analogue is given by
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 and denote the fox and rabbit populations, respectively, at time . If there were no rabbits, then one might expect that the foxes, lacking an adequate food supply, would decline in number according to
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 and ., i.e., proportional to the product . Thus, when rabbits are present, there is a supply of food, so foxes are added to the system at a rate , . Adding this last rate to (5) gives a model of the fox population
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
But when foxes are present, a model for the rabbit population is this equation decreased by , , that is, decreased by the rate at which the rabbits are eaten during their encounters with the foxes
This constitutes the system of nonlinear DEs
where , and 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) Model the spread of a contagious disease using the compartmental SIR model from epidemiology. See also notebooks/contagious_disease.jl.
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 is given by
where are the independent variables, is the unknown function, and denotes the partial derivative . Also partial derivatives of higher order like 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.
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 , then the PDE is said to be of order . Thus, for example, the equation is called a second-order equation, while is called a third-order equation.
Linearity: A PDE is called linear if in (6), is a linear function of the unknown function and all of its derivatives. For example, is a linear equation while 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 equations with unknown functions is called a system of equations.
Poisson's equation is a second-order PDE frequently used in theoretical physics. Given the Laplace operator in -dimensional space
it is defined by
where the initial condition is given and is the unknown solution.
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.