Finding Solutions
In the last chapter we learned what a differential equation says. A local rule assigns a slope at each possible time and state, and an initial condition specifies a point our solution must pass through. Drawing the slope field lets us begin to picture the possible histories. But how do we actually find one? How do we turn the local rule into a function we can evaluate, or a calculation we can carry out?
In one sense, that question is the subject of this entire book! But our first attempt will be deliberately modest. We will focus mostly on one unknown function and one first-order equation
We will take advantage of this simple situation to explore the different things one might want when asking for a solution---there's no one-size-fits-all technique, nor should there be! Sometimes we want a formula for an answer, something we can recognize from calculus or derive using its techniques, then plug things into and get precise predictions. Other times we may know that whatever formula exists is too complicated to be useful, or that it's essentially impossible to write down---in these cases we might prefer a numerical solution: an algorithm that follows the local rule to give us good approximations to the answer quickly, while avoiding thousands of pages of calculus and algebra. And other times we may find a simple plot reveals enough information that we don't need a formula or rigorous numerics at all.
We will spend a little more time on the 'formula' case here, but not because it is necessarily more important. This chapter is also a chance to put some familiar calculus back to work: antidifferentiation, the chain rule, and the product rule. The point will not be to memorize a new collection of formulas. It will be to look at an equation and ask: is there a piece of calculus here which we already know how to undo?
2.1Guessing and Checking Solutions
First things first: how do we confirm that we have a solution to a differential equation? If we are given a formula, we differentiate it and substitute into the equation to check that the two sides agree. If there is an initial condition, we check that too. We know how to differentiate elementary functions, so when someone proposes an elementary formula as a solution, we have a direct way to check their answer ourselves!
This opens up a possibility: guess and check could be a rigorous solution technique. We might recognize a function whose derivatives behave the way the equation asks, or try a few possibilities until something works. However we arrive at our guess, once we verify that it satisfies the equation and the initial condition, we have found a solution.
The simplest version of this idea is
We need a function which is equal to its own derivative, so
Thus
Recall the differential equation we placed beside its algebraic counterpart at the very beginning of the book:
At first this looks intimidating, since it asks for a sum of derivatives of
This suggests we might guess
Cancelling the exponential from both sides (since it is never zero, we can do this) reduces the differential equation to the algebraic equation
Its solutions are
Remembering other relationships from calculus can extend our ability to guess (and check) even more equations. For the normalized spring equation
the functions
Guessing and checking is a genuine solution technique, but not a systematic one: it works when we can recognize the right kind of function. So what else can we borrow from calculus? Not only remembered relationships, but the techniques themselves.
2.2Antidifferentiation
So far we have borrowed facts from calculus to help us guess. But we can also borrow the techniques of calculus to produce solutions more systematically. In the easiest case, the differential equation simply tells us the derivative of the function we are looking for:
and the important thing here is that the right-hand side depends only on
This is just the kind of problem calculus has always taught us to solve. We
have some mystery function
You have been solving differential equations this way since your first calculus course; we just did not usually call them differential equations.
The constant
For example, consider the initial value problem
Antidifferentiating gives
Thus
Sometimes even this tiny amount of differential-equation language is hidden by a little algebra. Suppose instead we are given
At first this is a relationship involving
And now we are back in the situation we already understand. Integrating gives
There was no special differential-equation trick here. We used algebra to put the equation into a familiar form, and then used calculus to undo the derivative.
There is another way to write the same reasoning which will be more useful
to us. The Fundamental Theorem of Calculus says that the total change from
Consequently, we obtain a result worth keeping close at hand.
Proposition 2.1 (Accumulating a known rate). Let
has exactly one solution on
Any solution must satisfy this formula, by the Fundamental Theorem of
Calculus calculation above. Conversely, differentiating the formula gives
This formula says something wonderfully simple: start with the value you already have, then add up all the change that happens along the way. It is the local-to-global idea from the beginning of the book, now made into a calculation.
Does writing a definite integral really count as finding the solution? Consider
Our formula gives
The integrand has no elementary antiderivative, so we cannot finish by
replacing the integral with a familiar combination of functions. But the
integral already defines a function! The Fundamental Theorem of Calculus
tells us its derivative, and its value at
This is an exact solution. If we want a decimal approximation to
2.3Separating Variables
We know what to do when the equation gives us
Equations whose rate depends only on the current value of
But now the function we are trying to find appears inside the integral! Can we rearrange the equation so that the integration becomes something we know how to do?
One possibility is to divide by
Think back to
Yet
We can check for this possibility before dividing. For
The value stays fixed because the rule keeps prescribing zero change.
So we first look for zeros of
Our calculation now applies on that interval; the constant solutions we found separately remain solutions of the original equation.
Integrating both sides, we obtain
The left side is a familiar substitution problem! The denominator
contains
The substitution turns the equation into
Now the integrand is a known function of the integration variable
The initial condition determines the constant. If
Notice what the integral gives us: the elapsed time expressed in terms of
the value of
This is the idea of separation of variables: arrange the equation so that each side can be integrated with respect to just one variable. The substitution we worked through is often written more briefly as
Here the
And the same move works for a larger class of equations. Suppose
After checking the constant solutions where
Integrating and making the same substitution on the left gives
Now the right side also asks us to integrate a function, but the two variables have been separated: each side is an antidifferentiation problem in one variable.
Definition 2.2 (Separable equations). A first-order equation is separable on a region if it can be written
On any part of the region where
and integrates both sides. Any values where
Let us first work through an example where we can finish by solving for
Before dividing by
Integrating both sides gives
This time the last relationship is easy to invert. Exponentiating and absorbing the possible sign into the arbitrary constant gives
Allowing
Now check what we have found:
We began the calculation on a short interval where division was allowed, but the resulting function satisfies the equation and initial condition on the whole real line.
Let us try another equation where the integration leaves us with a little more algebra:
Separating and integrating gives
The initial condition says
How do we extract
At
Differentiating verifies the equation:
The denominator
But separation does not always leave a relationship which is useful to invert. For example, suppose
Moving the
After integrating, we obtain
This relation specifies the solution even though we have not isolated
Definition 2.3 (Implicit and explicit solutions). An explicit solution gives the unknown directly as
whose differentiable branches
Before leaving separation, let us return to cooling. Newton's law said that
the rate of change of temperature is proportional to the difference between
the object's temperature and its surroundings, with
The repeated expression
We can find the constant solution
Thus
Now the qualitative story we told from the local rule is visible in a single formula. The exponential factor tends toward zero, so a hot object cools toward the room temperature while a cold object warms toward it. The same equation, and the same formula, contains both stories.
2.4Undoing the Product Rule
Separation was really the chain rule used in reverse. Can we play the same game with another familiar rule? Sometimes an equation contains the pieces of a product rule, but the product they came from has been broken apart. Consider
The two terms on the left look as though they came from differentiating a product. Indeed,
So we can group the entire left-hand side into one derivative:
Now antidifferentiation gives
Nothing new had to be invented here. We simply recognized the remains of a product rule and put the product back together.
Often the needed product is not visible until we create it. For example, look at
The left side is not currently the derivative of a product. Suppose we
multiply the whole equation by some function
If the left side is to equal
We recognize one function with exactly that derivative relationship:
or, after putting the product back together,
Both sides can now be antidifferentiated:
The multiplying function
We managed to invent the right multiplier for this equation, but was that good luck? In the next chapter we will make this construction systematic for a whole class of equations, and use it to prove that their initial value problems have exactly one solution.
First, though, we need another way to find answers. Our calculus techniques depend on recognizing a useful structure in the equation. What can we do when we do not find one? The slope field still gives us a direction at every point. Perhaps we can turn the act of following those directions into a calculation.
2.5Euler's Method
Let us try this on the initial value problem
This looks suspiciously like the sort of equation we should be able to
solve for homework. But the
Still, the differential equation answers one small question perfectly. At
the initial point
What can we do with one slope? The tangent-line approximation says that
for a short time
If we take
Of course, there is no reason to keep trusting the old slope once we arrive
at this new point. So we do something much more sensible: ask the
differential equation again! It gives us the slope at
In general, if our current approximation is
Definition 2.4 (Euler's method). For the initial value problem
There is nothing more hidden in the method: it is the familiar tangent-line
approximation, restarted over and over. Continuing our
There is something important hiding in this little table. The values
The step size
The method is quite easy to translate into code. The following Python loop says exactly what we just said: ask for a slope, use it to update the value, update the time, and repeat.
def euler(F, t0, y0, h, steps):
t = t0
y = y0
points = [(t, y)]
for _ in range(steps):
y = y + h * F(t, y)
t = t + h
points.append((t, y))
return points
def F(t, y):
return y * (1 - y) + 0.1 * t
points = euler(F, 0, 0.1, 0.5, 16)
The list points is the polygon drawn in the figure. There is no hidden
solver inside the code. This tiny loop is the solver.
Earlier, a Riemann sum gave us a way to approximate the accumulated change
when the rate was a known function of time. Euler's method has extended
that idea to a rate which depends on the unknown value as well. To see
this, add up the first
If
How much should we trust the result? We can test the method on equations we
already know how to solve, and we can repeat a computation with smaller and
smaller values of
We can now find solutions in several ways. A remembered function may give us a successful guess; a calculus rule may reconstruct an exact answer; a sequence of short steps may give us a useful numerical approximation. But these methods also leave us with questions.
If we cannot find a formula, is there nevertheless a solution to find? If we have checked one, could there be another with the same initial condition? And how far in time does the solution continue? Euler's update lets us ask for another step, but that alone does not tell us whether an exact solution exists at the time we are trying to reach.
These are questions about the differential equation itself, whether or not we can solve it explicitly. In the next chapter we will begin answering them.
Further Reading
Thomas W. Judson's open textbook, The ODE Project, Sections 1.2--1.4, develops separable equations, direction fields and phase lines, and numerical approximation through examples and activities.
Jiří Lebl's Notes on Diffy Qs, Chapter 1 gives a concise second pass through first-order equations, including implicit solutions, autonomous equations, and Euler's method.
MIT OpenCourseWare's 18.03SC Unit I offers another route through the same analytic, geometric, and numerical viewpoints, with free notes, videos, practice problems, and solutions.
Problems
The routine problems ask you to guess and check, use calculus to find solutions, and step numerically with Euler’s method. In the Python problems, begin with the supplied structure and make the computation your own.
Check Your Understanding
1Exponentials turn calculus into algebra
For each equation, try
The three exponential solutions you found for the third-order equation all
satisfy
2A spring with a different clock
Consider
Motivate a trigonometric guess, then verify that
Choose
What is the period of this motion? Check your answer directly from the formula rather than quoting a memorized spring formula.
3Accumulating a known rate
Solve each initial value problem exactly. Give an integral-defined answer when an elementary antiderivative is not available.
4Separate carefully
For each equation, find every constant solution before dividing, then find the remaining solutions and impose the initial condition.
In the previous part, identify the step which would have discarded two solutions if you had performed it too early.
5An implicit solution is still a solution
Separate
6Put the product back together
Solve each equation by recognizing or creating a product derivative.
Check the family you found in the previous part by substitution. Which member is the constant solution?
7Euler by hand
Apply Euler's method to
With
The exact solution is
Without recomputing, point to the entries of your table which show that Euler's method used its own approximate history to choose later slopes.
Explorations
8One equation, two methods
Consider
Rewrite the equation in separable form. First find any constant solutions. Then separate variables on intervals where the factor you divide by is nonzero, and solve.
Solve the same equation by multiplying by
Show that your two answers describe the same family, even if their constants look different. Which solution needed separate attention during separation? How does it appear in the product-rule answer?
Use either answer to find a solution satisfying
9Choosing a branch
Consider the equation
with two different initial conditions:
Separate and integrate for each initial condition. Show that both lead to the same implicit relation
Solve this relation for
For each answer, find the largest open interval containing
The formulas also give real values when
Python: From a Loop to Evidence
10Write Euler's method once
Complete the two missing update lines in this function.
def euler(F, t0, y0, h, steps):
t = t0
y = y0
ts = [t]
ys = [y]
for _ in range(steps):
# update y using the slope at the old point
# update t
ts.append(t)
ys.append(y)
return ts, ys
Test your function on
For each step size, compute the absolute error at
Change the right-hand side to
11Plot an implicit family
The separated equation in figure 2.3 produced the family
Use numpy.linspace to make grids of
G = Y + Y**3 / 3 - T**2 / 2
on the grid, and use plt.contour(T, Y, G, levels=[...]) to draw at least
five values of




