Ordinary Differential Equations
In many practical applications (physics, economics, engineering, applied science and so on), we know something about the relationship between a quantity and its rates of change, but we do not have an exact formula for the quantity itself. For example, a simple population model states that a population grows at a rate proportional to its current size; writing for the population at time , this becomes
where is the constant of proportionality. An equation like this, involving one (or more) derivatives of a function, is called a differential equation. Some other simple examples:
- (displacement of a particle undergoing simple harmonic motion);
- (temperature of an object sitting in a room at degrees);
- (value of an investment over time).
The whole point of this chapter is: given a differential equation for an unknown function, find an explicit formula (or formulae) for that function.
3.1 An introduction
Note
Definition
An ordinary differential equation is an equation expressed in terms of exactly one independent variable and one (or more) of the derivatives of a function of this variable. The order of an ordinary differential equation is the order of the highest derivative present.
Basically, an ODE is any equation with derivatives in it, and the order is just the highest derivative you can find. The equations are called 'ordinary' because they involve ordinary derivatives; this distinguishes them from partial differential equations, which involve partial derivatives (second year material). For example,
is an ODE of order 3 (independent variable , with a function of ), while
is an ODE of order 2. Notice how the power does not affect the order; only the highest derivative present matters.
Also note that the same ODE can be dressed up in several notations; the equations
all represent the same ODE.
Note
Definition
A solution to an th order ordinary differential equation is a function which is -times differentiable and satisfies the given equation.
Example. Consider the ODE
Then is a solution (differentiate it and you get back ). But so is , and ; each of these is called a particular solution. Every solution to this ODE can be written in the form
where ; this family of solutions is called the general solution. Basically, a particular solution is one specific function, whilst the general solution is the whole family with the arbitrary constant(s) still floating around.
In the example above, could be written explicitly as a function of , giving an explicit solution. This cannot always be done; sometimes we must settle for an implicit solution, where is only defined implicitly by some equation.
Example. Show that , given implicitly by the equation
is a particular solution to the ODE
To verify that solves the ODE, we first need . Implicitly differentiating both sides with respect to (using the chain rule on the right),
which is exactly the ODE. Hence the ODE is satisfied and is a (particular) solution. Note we only verified a given solution here; in Section 3.5 we will actually find the general solution to this ODE from scratch.
3.2 Initial value problems
In most practical applications, we also know the value of the unknown function (and possibly its derivatives) at some particular point. This extra information, together with the ODE, forms an initial value problem.
Note
Definition
An initial value problem is an th order ODE together with a set of values of the solution and its first derivatives at some fixed point . These values are called the initial conditions of the initial value problem.
'Initial value problem' is usually abbreviated as IVP. The strategy for solving an IVP is: find the general solution to the ODE (with its unspecified constants), then impose the initial conditions to pin down the constants. Note that an th order ODE needs conditions since the general solution has arbitrary constants.
Example. Solve the IVP
Integrating the ODE once,
where . Imposing gives . Integrating again,
where . Imposing gives . Therefore the solution to the IVP is
which is valid for all .
Not every IVP is this friendly. In general, three questions arise:
- Does the IVP have a solution at all?
- Is the solution unique?
- If the initial values are given at a point , how far on either side of does the solution extend?
The next two examples show that even 'simple' looking IVPs can misbehave.
Example. Solve the IVP
Assuming , we can separate:
The initial condition gives , and rearranging,
However, notice that the constant function is also a solution to the IVP (both sides are ). Hence this IVP does not have a unique solution.
Example. Solve the IVP
How far does the solution extend on either side of the point ?
The ODE says does not exist at , so the solution cannot cross . On the interval the general solution is , and gives . Hence
So the solution only extends over ; you could patch on for , but for practical applications the break in the domain at means we would not use it there.
3.3 Separable ODEs
A separable ODE is one where the two variables (say and ) can be separated, so that all the 's end up on one side of the equation and all the 's on the other. In general, a separable ODE is one that can be written in the form
To solve it, write
integrate both sides to obtain an implicit solution , and then (whenever possible) isolate to get the explicit solution. If initial conditions are given, use them to determine .
The fact that this symbolic manipulation with and 'works' traces back to the chain rule: , and integrating both sides with respect to turns into . Do not assume you can manipulate the symbols and in other creative ways and still get valid results.
Example. Solve the initial value problem
Separating the variables and integrating,
where ; this is the implicit solution. Imposing ,
so . Making the subject,
Therefore the explicit solution is .
Example. Solve the equation
Separating and simplifying,
where . In this case it is best to leave the solution in implicit form, since is not one-to-one; 'inverting' it would silently throw away solutions.
Example. (Newton's law of cooling)
(a) Newton's law of cooling states that the rate of heat loss of a body is proportional to the difference in temperature between the body and its surroundings. Set up an ODE for this and solve it.
(b) A hot object is placed into a room of temperature C. The object is initially too hot for the thermometer to measure, but after 6 minutes its temperature is C, and after 8 minutes it is C. What was the original temperature?
(a) Suppose is the temperature of the object at time , is the ambient (room) temperature and is the constant of proportionality. Then
This is separable:
where .
(b) Here , and . Substituting into the solution,
So and ; dividing the second equation by the first,
Then, from ,
Finally,
Therefore the initial temperature of the object was C.
3.4 First order linear ODEs
A first order linear ODE can be written in the form
where and are given functions of the single variable . The ODE is called linear because there are no non-linear terms (like , or ) involving or ; note that and are allowed to be as ugly as they like in .
The method for solving these is very slick:
- Write the ODE in the standard form above.
- Calculate (ignoring the constant of integration). This is called the integrating factor.
- Multiply the ODE through by :
By the product rule, the left-hand side always collapses to
- Integrate both sides and rearrange for . Do not forget the constant of integration in this step; if it is accidentally omitted then you lose half the solution.
Basically, the integrating factor is a magic multiplier engineered so that the messy left-hand side becomes the derivative of a single product ; this works because by the chain rule, which is exactly the coefficient needed for the product rule to run backwards.
Example. Solve .
The ODE is already in standard form with , so the integrating factor is
Multiplying through by and contracting the left-hand side,
where . Therefore the general solution is ; notice how forgetting the would have lost the entire family.
Example. Solve the IVP
First rewrite in standard form by dividing by :
The integrating factor is
It is important to simplify like this before continuing; leaving it as makes the next steps unusable.
Multiplying the standard form by ,
Imposing ,
so . Therefore
Note the solution is valid on or but never at ; in fact no real-valued solution of the original ODE can have in its domain.
Example. An investor has a salary of per year, expected to increase at per annum. An initial deposit of is invested in a program paying per annum, and the investor deposits of their salary each year. Find the amount invested after years (assuming interest and deposits are calculated continuously).
Let denote the dollars invested after years. Then
i.e. (rate of increase of investment) ( of investment) ( of salary). In standard form,
which is first order linear with integrating factor . Hence
Integrating the right-hand side by parts, with and (so ),
So , and dividing through,
Imposing gives , hence
Therefore after 10 years, the investment totals .
Example. Some ODEs are both separable and linear; solve both ways and check the answers agree.
Method 1 (separable). Write and separate:
Method 2 (linear). Here , so and
Both methods produce the same family ; the arbitrary constants just get relabelled along the way. So when an ODE is both types, use whichever method you spot first (separation is usually less writing).
3.5 Exact ODEs
Here is another approach to solving (some) first order ODEs. Suppose is a function of two variables and satisfying
where is a real constant. If we consider as a function of and differentiate both sides with respect to , then the chain rule from Chapter 1 gives
Denoting and by and respectively, we obtain the differential equation
Conversely, if we want to solve an ODE of this form and there happens to exist an with and , then the solution is simply . The difficulty is that this condition on and is not easy to verify directly. Fortunately, the mixed derivative theorem says that for a 'nice' ,
and this second condition is easy to check.
Note
Definition
An ordinary differential equation of the form
is called exact if
Note
Theorem
Suppose that an ordinary differential equation of the above form is exact. Then its solution is given by , where is a constant and is a function satisfying
Basically: an exact ODE is one whose left-hand side is secretly the total derivative of some two-variable function , and the exactness test (equality of the mixed partials) is how you detect this without knowing . Note the ODE can equivalently be written as or as .
Example. Show that the differential equation
is exact, and hence find its solution.
First rewrite the ODE as
and write and . Then
so the ODE is exact. Hence there is a function with and . Integrating with respect to (treating as a constant), and integrating with respect to (treating as a constant),
where the 'constants of integration' and are functions of and respectively. Comparing the two expressions,
and so the solution to the ODE is
where . (Technically should carry its own arbitrary constant , but it just merges into on the right-hand side, so it is customary to ignore it.) Since this is a quadratic in you could use the quadratic formula to write explicitly, but the answer is much cleaner left in implicit form.
Example. Solve the differential equation
Write and . Then
so the equation is exact. This time we use a slightly different approach to find . Integrating with respect to ,
To determine , differentiate this with respect to and compare with :
so , whence . Hence and the solution is
where . Notice how taking recovers , which is exactly the particular solution we verified back in Section 3.1; and here it is not possible to make explicit at all.
Example. Solve the differential equation
Write and . Since
the ODE is not exact. What happens if we barge ahead with the method regardless? Integrating with respect to gives , and then
forces , which contradicts being independent of ; no such exists.
Fortunately, not all is lost. Multiplying the whole ODE by gives
and since is never zero, this has the same solutions as the original. Checking the exactness test again with and ,
so the new equation is exact. Integrating with respect to ,
and comparing with shows . Therefore the solution is
where . In general, finding a multiplier that fixes a non-exact ODE like this is difficult and lies beyond the scope of this course; here it was handed to us.
Example. (Classify, then solve.) For each of the following, name the method (separable, linear or exact) before touching any algebra, then solve.
(a)
(b) , for
(c)
(d)
(a) The right-hand side factors as (function of )(function of ), so this is separable (it is not linear because of the ):
where . (The constant function is also a solution; separation quietly divided it away.)
(b) Dividing by gives , which is the linear standard form (it is not separable since the term stops the right side from factorising). The integrating factor is , so
(c) This is in the form with and ; checking the exactness test, , so it is exact. Integrating with respect to gives , and comparing with gives , so . The solution is
(d) This looks like none of the types, but since it is separable in disguise:
where (and we need for the log to make sense).
The decision order I use: try to separate first; if that fails, hunt for the linear standard form; if that also fails, rearrange into and run the exactness test.
3.6 Solving ODEs by using a change of variable [X]
This section is MATH1241/extension [X] material only, so imma keep it brief.
Not every first order ODE is separable, linear or exact, but some can be transformed into one of these types by a suitable change of variable; you solve the transformed equation for the new variable, then convert back.
Example. Use the substitution to solve
By the product rule, . Substituting (and using on the right),
Since , the general solution is
where .
Example. Solve
using the substitution .
The term means this is not linear in , but it will turn out linear in . Differentiating with respect to gives , so the ODE becomes
Since , the solution is
where . Notice how the substitution converted a nonlinear ODE in into a first order linear ODE in .
3.7 Modelling with first order ODEs
Many real-life problems can be analysed by converting them into mathematics; the theoretical framework (with all its simplifying assumptions) is called a mathematical model, and its reliability is judged by how well it predicts what actually happens. To construct one, you should
- describe accurately the data you have,
- decide exactly what information you want out of the model,
- decide which variables are dependent and which are independent, and
- describe how the dependent variables change as the independent ones vary (this is usually where the differential equation appears).
We have already built two models: Newton's law of cooling and the investment example in Section 3.4.
Mixing problems
Example. A martini is, in essence, a mixture of gin and vermouth. James Blond insists his martinis be prepared as follows: initially, 40 cc of gin are placed in a large container; then gin is poured in at 2 cc/sec while vermouth is poured in at 6 cc/sec. The mixture is constantly shaken (not stirred) and flows out at 4 cc/sec.
(a) Find an expression for the volume of vermouth in the container seconds after pouring commences.
(b) James likes his martini roughly two parts gin to three parts vermouth. How many seconds should elapse before he inserts a cocktail glass into the outflow?
(a) Let denote the volume of vermouth (in cc) at time ; we know . The key modelling equation for any mixing problem is
The inflow of vermouth is cc/sec. For the outflow, the total volume of liquid at time is
so the proportion (by volume) of vermouth in the container is , and since liquid leaves at cc/sec, vermouth leaves at cc/sec. Hence we obtain the IVP
This is first order linear with integrating factor
so
Imposing gives , hence
(b) Two parts gin to three parts vermouth means three-fifths of the liquid is vermouth, so we require
where we took the positive root of the quadratic. Therefore James should insert the glass about seconds after mixing begins.
Example. (Mixing with a changing volume.) A tank can hold 100 litres. Initially it holds 50 litres of pure water. Brine containing 2 grams of salt per litre runs in at 3 litres per minute, and the well-stirred mixture runs out at 1 litre per minute. How much salt does the tank contain at the moment it starts to overflow?
Let be the mass of salt (in grams) after minutes; . The volume is not constant here: it gains litres per minute, so the volume at time is litres. Salt flows in at g/min and flows out at (concentration)(outflow rate) g/min. Hence
The most common mistake in these problems is using a constant volume in the outflow concentration; whenever the inflow and outflow rates differ, the denominator must be a function of .
The ODE is linear with integrating factor
so
Imposing ,
so . The tank overflows when , i.e. at minutes, at which point
Therefore the tank contains grams of salt at the point of overflowing.
Population models
Suppose the city of Mathopolis initially has 3,000,000 inhabitants and (initially) grows at 2% per annum. Can we predict the population in 10, 20 or 100 years? We compare three models on this same data.
Example. (Model 1: exponential growth.) Assume the rate of change of population is proportional to the population, with constant growth rate :
This is separable:
(This model goes back to Thomas Malthus, 1798.) For Mathopolis, and , so ; after 100 years this predicts about 22.17 million people.
Criticisms: the model predicts indefinite growth, ignoring that resources and space are finite; and external factors (disease, disasters, wars) are ignored.
Example. (Model 2: limited growth.) Now suppose there is a critical population which, when exceeded, causes the population to decrease; below it the population increases. Try
where (so when and when ). Separating (in the case ),
where imposing gave (the case gives exactly the same formula). Note that as .
For Mathopolis, take (the maximum sustainable size). Since at ,
so and
Criticism: if is close to then , so the model says tiny populations grow fastest, which is silly.
Example. (Model 3: the logistic model.) To fix the small-population problem, try
where ; now is small when is small (Verhulst, 1838). Separating and using partial fractions on the left,
where imposing gives . Rearranging for ,
and substituting in then multiplying top and bottom by ,
Once again as . The resulting S-shaped curve is called a logistic curve: growth is approximately exponential at the start, then slows and approaches asymptotically.
For Mathopolis, gives , so and
Comparing the three forecasts (in millions):
| Initially | After 10 years | After 20 years | After 100 years | |
|---|---|---|---|---|
| Model 1 | 3.00 | 3.66 | 4.48 | 22.17 |
| Model 2 | 3.00 | 3.56 | 4.04 | 6.11 |
| Model 3 | 3.00 | 3.61 | 4.21 | 6.73 |
All three models still ignore external factors ( itself can shift with technology or climate). Notice how the more realistic the model, the harder the mathematics; at the extreme end, the (partial) differential equations modelling fluid flow (the Navier–Stokes equations) are so hard that existence of smooth solutions is a Millennium problem worth one million US dollars.
3.8 Second order linear ODEs with constant coefficients
We now consider a special class of second order equations, of the form
where and are real numbers. These arise naturally in wave mechanics and predator-prey models; you have already seen used to model simple harmonic motion.
The homogeneous case
We first look at the case when (i.e. for all ).
Note
Definition
A second order linear ODE with constant coefficients is said to be homogeneous if it is of the form
where and are real numbers.
It turns out we can always solve these. The first key observation:
Note
Lemma
If and are two solutions to the homogeneous equation, then any linear combination , where and are real numbers, is also a solution.
Proof. Let . Then
It can also be shown that every second order ODE has at most two linearly independent solutions (proved in second year); here two solutions are linearly independent if and only if they are not constant multiples of each other. So the entire game is: find two linearly independent solutions , and then is the general solution.
To hunt for a solution, we try a function that does not change too much when differentiated, since the terms on the left-hand side need to cancel each other out to give zero. If (with constant), then and , so substituting,
Hence is a solution if and only if is a root of this quadratic.
Note
Definition
The characteristic equation of the second order linear ODE is given by
Example. Solve .
The characteristic equation is
so . Hence and are solutions, and since they are linearly independent, the general solution is
where .
In that example the characteristic equation had two distinct real roots. Since and are real, there are three possibilities in general: two distinct real roots, a repeated real root, or a complex conjugate pair.
For a repeated real root , the second independent solution is . To verify this, note a repeated root satisfies both and (the vertex of the parabola); with , and , so
since both brackets vanish.
For complex roots (with ), the two exponential solutions are complex-valued, but we can extract real solutions using Euler's formula :
where and ; choosing and to be complex conjugates of each other makes and real. We summarise all three cases:
Note
Theorem
Consider the homogeneous ODE and let and denote the roots of the characteristic equation .
(i) If and are different real numbers, then the general solution is
(ii) If , then the general solution is
(iii) If and , where and , then the general solution is
Example. Solve the following differential equations:
(a) ,
(b) , with initial conditions and .
(a) The characteristic equation has roots
so by case (iii) the general solution is
where .
(b) The characteristic equation factorises as , so is a repeated root and
Differentiating (for the second initial condition),
Now gives , and gives , so . Therefore the solution to the IVP is
The non-homogeneous case
Now suppose is not identically zero. The main idea is illustrated by an example.
Example. Solve the equation
Since derivatives of polynomials are polynomials, it seems likely some particular solution is a polynomial, and a little thought shows its degree can be at most one. So we look for a particular solution of the form . Then and , and substituting,
Equating coefficients: gives , and then gives . Hence .
Are there other solutions? Yes. The associated homogeneous equation has solution (from the earlier example), and is also a solution:
Therefore the general solution is
where (that this really is all the solutions is explained in the linear algebra subsection below).
The general algorithm for :
- Find the solution to the corresponding homogeneous equation (via the characteristic equation).
- Find a particular solution (by guessing its form and determining the unknown coefficients — the method of undetermined coefficients).
- The general solution is
Always perform Step 1 before Step 2; without knowing you cannot tell whether your guess for secretly solves the homogeneous equation (the reason will become obvious shortly).
Example. Solve the ODE
First, the characteristic equation has roots , so
Second, since the right-hand side is an exponential, try ; then and , so substituting,
Therefore the general solution is
where .
Given a forcing term , the correct form to guess for is:
| Guess for particular solution | |
|---|---|
| (polynomial of degree ) | (polynomial of degree ) |
| or | |
| or |
If any term of the guess for is a solution to the homogeneous ODE, then multiply the guess by ; if any term of the new guess is still a solution to the homogeneous ODE, multiply by again.
Example. Solve the ODE
The characteristic equation has roots , so
Since the right-hand side is a multiple of , the natural guess is — but this is a homogeneous solution (set , in ), so substituting it produces on the left-hand side and the guess fails. Following the rule, multiply by and try instead. Then
and substituting,
Therefore the general solution is
where .
Example. Solve the ODE
The characteristic equation factorises as , giving the repeated root , so
The first guess solves the homogeneous equation; multiplying by gives , which also solves it (set , ). So multiply by once more: , which is finally not a homogeneous solution. Then
and substituting,
Therefore the general solution is
where .
Example. Write down the form of a particular solution to
(without evaluating the coefficients).
The characteristic equation has roots
so . The table suggests the guess — but every term of this solves the homogeneous equation. Multiplying by ,
which no longer lies in the homogeneous solution space; this is the form we seek. Notice how this collision was invisible until was computed — this is exactly why Step 1 comes first.
Example. Find a particular solution to
From before, . The table suggests ; now itself is not a homogeneous solution, but the and terms are, so the whole guess must be multiplied by twice:
When the forcing term contains a polynomial, you must multiply the entire polynomial guess by (or ), not just the offending terms.
There is a slick way to find the coefficients here: writing , direct computation gives
so the ODE reduces to . Integrating twice, , and the and pieces are exactly . Hence , , and
Example. Solve the ODE
The characteristic equation has roots , so
The naive guess collides with completely, so we try
Differentiating twice,
so substituting (the -terms cancel against ),
Hence and , and the general solution is
where . Notice the term: the forcing frequency matches the natural frequency of the system, so the oscillations grow linearly without bound. This is resonance, which we study properly in the next subsection.
Example. Solve the IVP
The characteristic equation gives , so
Since is not a homogeneous solution, try :
so and the general solution is .
Impose the initial conditions on the full general solution ; imposing them on alone and adding afterwards gives the wrong constants. Now , so the conditions give
i.e. and . Subtracting, , so and . Therefore the solution to the IVP is
An application: vibrations and resonance
Many structures have a natural frequency of vibration. If an external agent forces them to vibrate at or near this frequency, large oscillations build up and resonance occurs; this can collapse bridges, and it is the 'trick' singers use to shatter wine glasses.
Example. A spring is mounted to a fixed point with an object of mass suspended from it. Let denote the vertical displacement from the equilibrium position (positive above it). Newton's second law and Hooke's law give
where depends only on the mass and the stiffness of the spring. The object is pulled down 4 units from equilibrium and released from rest; find for .
The initial conditions are and . The characteristic equation has roots (so , ), and by the three-case theorem,
Differentiating,
Now gives , so (since ), and gives . Therefore
The object oscillates between forever with period ; this is simple harmonic motion.
Example. Same scenario, except the point now vibrates up and down with vertical displacement ; a simple physical argument then gives
Describe the motion, given and .
We already have ; the behaviour of splits into two cases depending on whether the forcing frequency matches the natural frequency.
Case 1: . Try . Since ,
so and . Then , and imposing gives , while gives . Hence
This is just another stable, bounded oscillation.
Case 2: . The guess from Case 1 now collides with , so multiply by : try . Substituting (the -terms cancel just like in the example),
so and , giving . Imposing the initial conditions on : , and
so gives . Hence
As increases, the amplitude of the term grows without bound and the system becomes unstable; this is resonance. Basically: force a system at its own natural frequency and every push arrives at exactly the right moment, so energy keeps accumulating.
A connection with linear algebra
Two claims made earlier are still unproved: (A) a second order homogeneous ODE has at most two linearly independent solutions, and (B) every solution to the non-homogeneous equation has the form . Claim (A) is proved in MATH2501; claim (B) we can prove now using linear algebra (Chapter 7 of the algebra notes).
Consider , let be the vector space of all infinitely differentiable functions , and define the linear transformation by
Observe that
So the general solution to the homogeneous equation is exactly the kernel of — a subspace of . This is why the superposition Lemma from earlier works: kernels are closed under linear combinations, so of course is again a solution. Similarly,
so the non-homogeneous ODE has a solution if and only if ; and confirms is always a solution.
Proof. (of claim (B)). Suppose is any solution and is some particular solution, so and . Then
so . But every function in the kernel is a homogeneous solution, so for some , i.e. .
Basically, the solution set of the non-homogeneous equation is the shifted kernel ; this is the same picture as the solution set of being one particular solution plus the kernel of .