Ran Wei/ Calculus/Module 13
中文
Calculus · Part III · Integrals

Module 13Differential equations

Write down the equations that describe growth, cooling, falling and mixing, and read their solutions from a picture before you solve anything. Then compute solutions step by step with Euler’s method, solve the main kinds of equation exactly, from separable and linear equations to the vibrations of a spring, and check every answer by substituting it back.

⏱ 270 minYou need: Modules 1 to 12, especially the rules of differentiation (Modules 4 to 6) and the techniques of integration (Modules 10 and 11)

In this module you will

  • Explain what a differential equation, its order and its solutions are, and check a solution by substituting it
  • Model growth, cooling, a falling body and a mixing tank with differential equations
  • Read direction fields, find equilibrium solutions and decide whether they are stable
  • Approximate solutions with Euler’s method, and explain why its error is proportional to the step size
  • Solve separable, logistic and first-order linear equations, and second-order linear equations with constant coefficients
  • Solve and check differential equations with SymPy, and numerically
1

What a differential equation is

Section 1.3 dropped a ball and gave the distance it falls in tt seconds: s(t)=4.9t2s(t) = 4.9t^2 metres. Physics does not hand you that formula. What it gives is a statement about rates: near the Earth’s surface, if air resistance is negligible, a falling body has the constant acceleration g≈9.8g \approx 9.8 m/s². In symbols,

s′′(t)=9.8.s''(t) = 9.8.

This is an equation for an unknown function, s,s\mathclose{\text{,}} and it involves a derivative of s.s\mathclose{\text{.}} Integrating twice (Module 10) gives s′(t)=9.8t+C1s'(t) = 9.8t + C_1 and s(t)=4.9t2+C1t+C2.s(t) = 4.9t^2 + C_1t + C_2\mathclose{\text{.}} A ball dropped from rest has s(0)=0s(0) = 0 and s′(0)=0,s'(0) = 0\mathclose{\text{,}} so C2=0C_2 = 0 and C1=0:C_1 = 0\mathclose{\text{:}} s(t)=4.9t2,s(t) = 4.9t^2\mathclose{\text{,}} the formula of Module 1.

Module 6 met another such equation, y′=ky,y' = ky\mathclose{\text{,}} the law of exponential growth and decay, and checked that y=Cekty = Ce^{kt} satisfies it. Most laws of science are statements about rates of change: Newton’s laws of motion, the laws of cooling and of radioactive decay, the laws of electric circuits. Their natural form is an equation like these two, and this module is about finding the functions they describe.

Definition 13.1Differential equation

A differential equation is an equation that involves an unknown function and one or more of its derivatives. Its order is the order of the highest derivative in it.

So y′=kyy' = ky and y′=t−yy' = t - y have order 1, and s′′=9.8s'' = 9.8 and mx′′+cx′+kx=0mx'' + cx' + kx = 0 (a vibrating spring, Section 13.8) have order 2. In this module the unknown is a function of one variable, usually time t;t\mathclose{\text{;}} such equations are called ordinary differential equations. Equations for functions of several variables, with partial derivatives (Module 17), are partial differential equations, and beyond this course. Following custom, the equations write yy for y(t)y(t) and y′y' for dy/dt:dy/dt\mathclose{\text{:}} y′=t−yy' = t - y means y′(t)=t−y(t)y'(t) = t - y(t) for every tt considered.

Definition 13.2Solution and initial value problem

A solution of a differential equation on an open interval II is a function that has the derivatives the equation involves at every point of II and makes the equation true for every tt in I.I\mathclose{\text{.}} A formula, with arbitrary constants, that gives every solution is the general solution; any one solution is a particular solution. An initial value problem asks for the solution that also satisfies initial conditions at a time t0:t_0\mathclose{\text{:}} y(t0)=y0y(t_0) = y_0 for a first-order equation, and y(t0)=y0y(t_0) = y_0 and y′(t0)=v0y'(t_0) = v_0 for a second-order one.

t0t_0 and y0y_0 are read “t nought” and “y nought”. To check that a function is a solution, substitute it: compute its derivatives, put everything into the equation, and see that the two sides agree for every t.t\mathclose{\text{.}}

Example 13.1Checking a solution✓ Checked

Show that y=t−1+Ce−ty = t - 1 + Ce^{-t} is a solution of y′=t−yy' = t - y for every constant C,C\mathclose{\text{,}} and find the solution with y(0)=1.y(0) = 1\mathclose{\text{.}}

Differentiate: y′=1−Ce−t.y' = 1 - Ce^{-t}\mathclose{\text{.}} The right side of the equation is

t−y=t−(t−1+Ce−t)=1−Ce−t.\begin{aligned} t - y &= t - \big(t - 1 + Ce^{-t}\big) \\ &= 1 - Ce^{-t}. \end{aligned}

The two sides agree for every t,t\mathclose{\text{,}} so every function of the family is a solution on (−∞,∞).(-\infty, \infty)\mathclose{\text{.}} For the initial condition, y(0)=0−1+C=C−1,y(0) = 0 - 1 + C = C - 1\mathclose{\text{,}} which is 1 when C=2.C = 2\mathclose{\text{.}} The solution is

y=t−1+2e−t.y = t - 1 + 2e^{-t}.

Section 13.7 shows that the family contains every solution: it is the general solution.

Example 13.2A second-order equation✓ Checked

Show that x=cos⁡3tx = \cos 3t and x=sin⁡3tx = \sin 3t are solutions of x′′+9x=0,x'' + 9x = 0\mathclose{\text{,}} and find the solution with x(0)=2x(0) = 2 and x′(0)=3.x'(0) = 3\mathclose{\text{.}}

For x=cos⁡3t,x = \cos 3t\mathclose{\text{,}} the chain rule gives x′=−3sin⁡3tx' = -3\sin 3t and x′′=−9cos⁡3t,x'' = -9\cos 3t\mathclose{\text{,}} so x′′+9x=−9cos⁡3t+9cos⁡3t=0.x'' + 9x = -9\cos 3t + 9\cos 3t = 0\mathclose{\text{.}} For x=sin⁡3t,x = \sin 3t\mathclose{\text{,}} x′′=−9sin⁡3t,x'' = -9\sin 3t\mathclose{\text{,}} and again x′′+9x=0.x'' + 9x = 0\mathclose{\text{.}} The same holds for x=C1cos⁡3t+C2sin⁡3t,x = C_1\cos 3t + C_2\sin 3t\mathclose{\text{,}} whatever the constants C1C_1 and C2:C_2\mathclose{\text{:}} its second derivative is −9x.-9x\mathclose{\text{.}} Now fit the two conditions. x(0)=C1,x(0) = C_1\mathclose{\text{,}} so C1=2.C_1 = 2\mathclose{\text{.}} And

x′(t)=−3C1sin⁡3t+3C2cos⁡3t,x'(t) = -3C_1\sin 3t + 3C_2\cos 3t,

so x′(0)=3C2=3x'(0) = 3C_2 = 3 and C2=1.C_2 = 1\mathclose{\text{.}} The solution is x=2cos⁡3t+sin⁡3t.x = 2\cos 3t + \sin 3t\mathclose{\text{.}} A second-order equation takes two conditions, and its solutions here have two constants; Section 13.8 shows that this is no accident.

Watch out

A solution must satisfy the equation at every tt of an interval, not at a few points. The function y=t2y = t^2 is not a solution of y′=2y:y' = 2y\mathclose{\text{:}} here y′=2ty' = 2t and 2y=2t2,2y = 2t^2\mathclose{\text{,}} which agree at t=0t = 0 and at t=1,t = 1\mathclose{\text{,}} but at t=2t = 2 they are 4 and 8.

When there is exactly one solution

In Example 13.1 exactly one function of the family has y(0)=1.y(0) = 1\mathclose{\text{.}} For first-order equations written as y′=F(t,y),y' = F(t, y)\mathclose{\text{,}} exactly one solution through a given point is the usual situation, and a theorem says when it is guaranteed. It needs one new piece of notation: Fy,F_y\mathclose{\text{,}} read “F sub y”, denotes the derivative of F(t,y)F(t, y) with respect to y,y\mathclose{\text{,}} with tt held fixed as if it were a constant. For F(t,y)=t−y2,F(t, y) = t - y^2\mathclose{\text{,}} Fy=−2y.F_y = -2y\mathclose{\text{.}} (This is a partial derivative, the subject of Module 17.)

Theorem 13.1Existence and uniqueness

Suppose that FF and FyF_y are continuous on an open rectangle R,R\mathclose{\text{,}} the set of points (t,y)(t, y) with a<t<ba < t < b and c<y<d,c < y < d\mathclose{\text{,}} that contains the point (t0,y0).(t_0, y_0)\mathclose{\text{.}} The ends a,a\mathclose{\text{,}} b,b\mathclose{\text{,}} cc and dd may be infinite, so RR may be the whole plane. Then the initial value problem

y′=F(t,y),y(t0)=y0y' = F(t, y), \qquad y(t_0) = y_0

has a solution on some open interval containing t0,t_0\mathclose{\text{,}} and only one: two solutions of the problem whose graphs lie in RR agree on every open interval containing t0t_0 on which both are defined.

The proof, by a sequence of better and better approximations, belongs to a course on differential equations; this series uses the theorem without proof. Outside RR it promises nothing, which is why the graphs must stay in R.R\mathclose{\text{.}} Two examples show what it promises and what it does not.

  • The interval can be short. F(t,y)=y2F(t, y) = y^2 and Fy=2yF_y = 2y are continuous everywhere, yet the solution of y′=y2,y' = y^2\mathclose{\text{,}} y(0)=1,y(0) = 1\mathclose{\text{,}} is y=11−ty = \dfrac{1}{1 - t} (check: y′=1(1−t)2=y2),y' = \dfrac{1}{(1 - t)^2} = y^2\mathclose{\text{),}} which exists only for t<1:t < 1\mathclose{\text{:}} it blows up, growing without bound as tt approaches 1. Nothing in the equation warns you.
  • Without the hypothesis on Fy,F_y\mathclose{\text{,}} uniqueness can fail. The problem y′=3y2/3,y' = 3y^{2/3}\mathclose{\text{,}} y(0)=0,y(0) = 0\mathclose{\text{,}} has two solutions, y=0y = 0 and y=t3:y = t^3\mathclose{\text{:}} for y=t3,y = t^3\mathclose{\text{,}} y′=3t2y' = 3t^2 and 3y2/3=3(t3)2/3=3t23y^{2/3} = 3(t^3)^{2/3} = 3t^2 (with y2/3y^{2/3} the square of the real cube root). Here Fy=2y−1/3F_y = 2y^{-1/3} is not defined at y=0.y = 0\mathclose{\text{.}}

Uniqueness has a picture. Where FF and FyF_y are continuous, the graphs of two different solutions of y′=F(t,y)y' = F(t, y) never cross or touch: at a common point both would solve the same initial value problem, and so they would be the same solution.

2

Models

Most differential equations in science come from one principle: a quantity changes at the rate at which it is created or flows in, minus the rate at which it is destroyed or flows out. Writing that sentence in symbols is modelling, and the equation is a model: a simplified description, good when its assumptions hold. Four models recur in this module. Their numbers are hypothetical, chosen so that the arithmetic stays clean.

Growth and decay. A population with plenty of food and space has births and deaths in proportion to its size, so it changes at a rate proportional to its size: y′=ky,y' = ky\mathclose{\text{,}} where k,k\mathclose{\text{,}} the birth rate minus the death rate per individual, is positive when births outnumber deaths. The constant kk is measured per unit of time: with tt in years, k=0.02k = 0.02 per year means that the population grows at 2% of its current size per year. In a radioactive sample, each atom has the same chance of decaying in each second, so the number decaying per second is proportional to the number left: y′=kyy' = ky with k<0,k < 0\mathclose{\text{,}} now per second (Module 6).

Newton’s law of cooling. A hot drink cools quickly when it is much hotter than the room, and slowly as it approaches room temperature. Newton’s law of cooling makes the rate proportional to the difference: if T(t)T(t) is the temperature of an object in surroundings at a constant temperature Ts,T_s\mathclose{\text{,}} then

dTdt=−k(T−Ts),\frac{dT}{dt} = -k(T - T_s),

with a constant k>0k > 0 that depends on the object and its surroundings, measured per unit of time (per minute, say). The sign is right: when T>TsT > T_s the right side is negative and TT falls; when T<Ts,T < T_s\mathclose{\text{,}} TT rises. Like every model, this one is an approximation; it ignores, for example, that the outside of a cup cools faster than the inside.

A falling body with air resistance. Take downwards as positive. A body of mass mm falling at speed vv feels its weight mgmg pulling down and air resistance pushing up. For small, slow bodies the resistance is roughly proportional to the speed, cvcv with a constant c>0c > 0 in kilograms per second (so that cvcv is a force in newtons), and Newton’s second law (mass times acceleration equals the total force) gives

mdvdt=mg−cv.m\frac{dv}{dt} = mg - cv.

The speed stops changing when mg−cv=0,mg - cv = 0\mathclose{\text{,}} at the terminal velocity vT=mg/c.v_T = mg/c\mathclose{\text{.}} Suppose c/m=0.2c/m = 0.2 per second: dividing by m,m\mathclose{\text{,}} v′=9.8−0.2v,v' = 9.8 - 0.2v\mathclose{\text{,}} and vT=49v_T = 49 m/s. For large, fast bodies such as a skydiver, a resistance proportional to v2v^2 fits better (Exercise 13.11).

Mixing. A stirred tank with liquid flowing in and out:

Example 13.3A mixing tank✓ Checked

A tank holds 100 litres of salt water containing 5 kg of dissolved salt. Salt water with 0.2 kg of salt per litre flows in at 3 litres per minute; the tank is stirred so that it stays uniform, and the mixture flows out at the same rate. Write an initial value problem for the amount of salt, y(t)y(t) kg, after tt minutes, and find the amount at which it would stop changing.

The volume stays at 100 litres, since 3 litres per minute flow in and 3 flow out. Salt flows in at 0.2×3=0.60.2 \times 3 = 0.6 kg per minute. At time tt the concentration in the tank is y/100y/100 kg per litre, so salt flows out at y100×3=0.03y\tfrac{y}{100} \times 3 = 0.03y kg per minute. Rate of change equals rate in minus rate out:

y′=0.6−0.03y,y(0)=5.y' = 0.6 - 0.03y, \qquad y(0) = 5.

Every term is in kg per minute, as it should be. The amount stops changing when 0.6−0.03y=0,0.6 - 0.03y = 0\mathclose{\text{,}} at y=20y = 20 kg; the tank then has the inflow’s concentration, 20/100=0.220/100 = 0.2 kg per litre. The constant function y=20y = 20 is a solution, an equilibrium (Section 13.3). Exercise 13.6 finds how yy gets there.

Key idea

Rate of change = rate in − rate out. Before you solve a model, check that every term has the same units, and that the signs push the quantity the way it must move.

Watch out

A wrong sign gives a model that runs away. T′=k(T−Ts)T' = k(T - T_s) with k>0k > 0 makes a hot cup of tea heat up further, faster and faster. Ask which way the quantity must move, and check that the equation agrees. And keep units consistent: with flows in litres per minute, tt is in minutes, and a rate per hour must be converted first.

3

Direction fields and equilibria

You can draw the solutions of y′=F(t,y)y' = F(t, y) before you solve it. At every point (t,y)(t, y) the equation tells you the slope that a solution through that point must have. For y′=t−y,y' = t - y\mathclose{\text{,}} the slope at (0,1)(0, 1) is 0−1=−1;0 - 1 = -1\mathclose{\text{;}} at (1,1)(1, 1) it is 0; at (2,1)(2, 1) it is 1. Draw a short segment with that slope at each point of a grid, and the solutions appear as curves that follow the segments (Figure 13.1).

Definition 13.3Direction field

The direction field, or slope field, of y′=F(t,y)y' = F(t, y) is the picture with a short line segment of slope F(t,y)F(t, y) drawn at each point (t,y)(t, y) of a grid. The graph of a solution is tangent, at each of its points, to the direction field there.

Two direction fields, with solutions drawn through them. Left: y' = t - y. Every solution approaches the line y = t - 1 (orange), which is itself a solution; the blue curve is the solution through (0, 1) from Example 13.1. Right: y' = (y - 1)(y - 3). The slope depends only on y. The constant solutions are y = 1 (stable, green) and y = 3 (unstable, red): the solutions that start below 3 approach 1, and those that start above 3 grow without bound.
Figure 13.1

Two direction fields, with solutions drawn through them. Left: y′=t−y.y' = t - y\mathclose{\text{.}} Every solution approaches the line y=t−1y = t - 1 (orange), which is itself a solution; the blue curve is the solution through (0,1)(0, 1) from Example 13.1. Right: y′=(y−1)(y−3).y' = (y - 1)(y - 3)\mathclose{\text{.}} The slope depends only on y.y\mathclose{\text{.}} The constant solutions are y=1y = 1 (stable, green) and y=3y = 3 (unstable, red): the solutions that start below 3 approach 1, and those that start above 3 grow without bound.

On the left of Figure 13.1 the segments are horizontal along the line t−y=0,t - y = 0\mathclose{\text{,}} that is, y=t;y = t\mathclose{\text{;}} more generally the slope is the same number mm all along the line t−y=m.t - y = m\mathclose{\text{.}} Curves along which the slope is constant are isoclines, and they make direction fields easy to sketch by hand: draw an isocline, and put segments of its slope along it. The isocline for m=1,m = 1\mathclose{\text{,}} the line y=t−1,y = t - 1\mathclose{\text{,}} is special: its own slope is 1, the slope that the field asks for along it, so it is a solution, the one with C=0C = 0 in Example 13.1. The picture shows every other solution approaching it as tt grows, which agrees with the formula y=t−1+Ce−t:y = t - 1 + Ce^{-t}\mathclose{\text{:}} the term Ce−tCe^{-t} dies away.

Example 13.4Reading a direction field✓ Checked

For y′=t−y:y' = t - y\mathclose{\text{:}} (a) where do solutions increase, and where do they decrease? (b) Where does the solution through (0,1)(0, 1) have its lowest point?

(a) A solution increases where y′>0,y' > 0\mathclose{\text{,}} that is, where t−y>0:t - y > 0\mathclose{\text{:}} below the line y=t.y = t\mathclose{\text{.}} Above that line, solutions decrease. In Figure 13.1 the segments slope upwards below the line y=ty = t and downwards above it.

(b) The solution through (0,1)(0, 1) starts above the line y=t,y = t\mathclose{\text{,}} so it decreases at first; its lowest point is where y′=0,y' = 0\mathclose{\text{,}} on the isocline y=t.y = t\mathclose{\text{.}} With the formula y=t−1+2e−ty = t - 1 + 2e^{-t} of Example 13.1, that is where t−1+2e−t=t,t - 1 + 2e^{-t} = t\mathclose{\text{,}} that is, e−t=12,e^{-t} = \tfrac12\mathclose{\text{,}} so t=ln⁡2,t = \ln 2\mathclose{\text{,}} and there y=t=ln⁡2.y = t = \ln 2\mathclose{\text{.}} The lowest point is (ln⁡2,ln⁡2)≈(0.693,0.693):(\ln 2, \ln 2) \approx (0.693, 0.693)\mathclose{\text{:}} the bottom of the blue curve in Figure 13.1.

Equilibria and stability

When FF does not depend on t,t\mathclose{\text{,}} the equation y′=f(y)y' = f(y) is called autonomous. Its slope depends only on the height y,y\mathclose{\text{,}} so its direction field is the same along every horizontal line (Figure 13.1, right). All four models of Section 13.2 are autonomous.

Definition 13.4Equilibrium and stability

An equilibrium solution of y′=f(y)y' = f(y) is a constant solution y=y∗y = y^* (read “y star”). Its derivative is 0, so the equilibria are the numbers y∗y^* with f(y∗)=0.f(y^*) = 0\mathclose{\text{.}} An equilibrium is stable if every solution that starts close enough to it approaches it as t→∞,t \to \infty\mathclose{\text{,}} and unstable if some solutions that start as close to it as you like move away from it.

Between two neighbouring equilibria, a continuous ff has no zero, so it has one sign throughout (by the Intermediate Value Theorem of Module 3). So every solution there moves steadily up if f>0,f > 0\mathclose{\text{,}} or steadily down if f<0;f < 0\mathclose{\text{;}} and by uniqueness it never crosses an equilibrium. A sketch of the yy-axis with arrows, up where f>0f > 0 and down where f<0,f < 0\mathclose{\text{,}} is the equation’s phase line: it shows at a glance where every solution goes. The derivative of ff gives a quick test.

Theorem 13.2A test for stability

Let ff have a continuous derivative, and let f(y∗)=0.f(y^*) = 0\mathclose{\text{.}} If f′(y∗)<0,f'(y^*) < 0\mathclose{\text{,}} the equilibrium y∗y^* of y′=f(y)y' = f(y) is stable; if f′(y∗)>0,f'(y^*) > 0\mathclose{\text{,}} it is unstable.

The idea of the proof. If f′(y∗)<0,f'(y^*) < 0\mathclose{\text{,}} then f′<0f' < 0 on an interval around y∗y^* (because f′f' is continuous), so ff is decreasing there (Module 8). Since f(y∗)=0,f(y^*) = 0\mathclose{\text{,}} ff is positive on the part of that interval below y∗y^* and negative on the part above it: solutions a little below y∗y^* rise towards it, and solutions a little above fall towards it. If f′(y∗)>0f'(y^*) > 0 the signs are reversed and solutions move away. That a solution moving towards y∗y^* actually reaches it in the limit, rather than stopping short, takes two more facts: a function that keeps increasing but stays below a bound has a limit (for sequences, this is the Monotone Convergence Theorem of Module 14), and that limit must be a zero of f,f\mathclose{\text{,}} which on this interval only y∗y^* is. The linear approximation of Module 7 shows the mechanism: near y∗,y^*\mathclose{\text{,}} f(y)≈f′(y∗)(y−y∗),f(y) \approx f'(y^*)(y - y^*)\mathclose{\text{,}} so the distance u=y−y∗u = y - y^* obeys u′≈f′(y∗) u,u' \approx f'(y^*)\,u\mathclose{\text{,}} exponential decay if f′(y∗)<0f'(y^*) < 0 and growth if f′(y∗)>0.f'(y^*) > 0\mathclose{\text{.}}

Example 13.5Equilibria of y′=(y−1)(y−3)y' = (y - 1)(y - 3)✓ Checked

Find the equilibria of y′=(y−1)(y−3),y' = (y - 1)(y - 3)\mathclose{\text{,}} decide whether they are stable, and describe the solutions.

Here f(y)=(y−1)(y−3)=y2−4y+3,f(y) = (y - 1)(y - 3) = y^2 - 4y + 3\mathclose{\text{,}} which is 0 at y=1y = 1 and y=3:y = 3\mathclose{\text{:}} these are the equilibria. Since f′(y)=2y−4,f'(y) = 2y - 4\mathclose{\text{,}} f′(1)=−2<0f'(1) = -2 < 0 and f′(3)=2>0,f'(3) = 2 > 0\mathclose{\text{,}} so 1 is stable and 3 is unstable.

The phase line confirms it and says more. For y<1y < 1 both factors are negative, so f>0f > 0 and solutions rise towards 1. For 1<y<3,1 < y < 3\mathclose{\text{,}} f<0f < 0 and solutions fall towards 1. For y>3,y > 3\mathclose{\text{,}} f>0f > 0 and solutions rise away from 3, faster and faster: they grow without bound, as in Figure 13.1. So every solution that starts below 3 approaches 1, and every solution that starts above 3 escapes.

Watch out

An equilibrium is where f(y)=0,f(y) = 0\mathclose{\text{,}} not where f′(y)=0;f'(y) = 0\mathclose{\text{;}} the derivative only decides stability. And when f′(y∗)=0f'(y^*) = 0 the test says nothing: y′=−y3,y' = -y^3\mathclose{\text{,}} y′=y3y' = y^3 and y′=y2y' = y^2 all have f′(0)=0,f'(0) = 0\mathclose{\text{,}} yet 0 is stable for the first, unstable for the second, and for the third it attracts the solutions below it and repels those above (so it is unstable). Use the signs of ff on each side instead.

The widget at the end of Section 13.4 draws the direction field of five equations, or of one that you type, and the solution through any point you click.

4

Euler’s method

Most differential equations have no solution formula, and for those that have one, a numerical solution is often all that an application needs. The simplest numerical method turns the direction field into an algorithm.

Start at the point (t0,y0).(t_0, y_0)\mathclose{\text{.}} The equation gives the slope of the solution there, F(t0,y0),F(t_0, y_0)\mathclose{\text{,}} so you know the solution’s tangent line at that point. Follow the tangent line for a short time h,h\mathclose{\text{,}} the step size. By the linear approximation of Section 7.2,

y(t0+h)≈y0+h F(t0,y0).y(t_0 + h) \approx y_0 + h\,F(t_0, y_0).

Call this value y1,y_1\mathclose{\text{,}} and the new time t1=t0+h.t_1 = t_0 + h\mathclose{\text{.}} At (t1,y1)(t_1, y_1) the equation gives a new slope, F(t1,y1);F(t_1, y_1)\mathclose{\text{;}} follow it for another step of length h,h\mathclose{\text{,}} and so on.

Definition 13.5Euler’s method

To approximate the solution of y′=F(t,y),y' = F(t, y)\mathclose{\text{,}} y(t0)=y0,y(t_0) = y_0\mathclose{\text{,}} choose a step size h>0h > 0 and compute, for n=0,1,2,…,n = 0, 1, 2, \dots\mathclose{\text{,}}

tn+1=tn+h,yn+1=yn+h F(tn,yn).\begin{aligned} t_{n+1} &= t_n + h, \\ y_{n+1} &= y_n + h\,F(t_n, y_n). \end{aligned}

The number yny_n is the approximation to y(tn).y(t_n)\mathclose{\text{.}}

Example 13.6Euler’s method by hand✓ Checked

Use Euler’s method with h=0.5h = 0.5 to approximate y(2)y(2) for y′=t−y,y' = t - y\mathclose{\text{,}} y(0)=1,y(0) = 1\mathclose{\text{,}} and compare with the exact solution of Example 13.1.

Here F(t,y)=t−y,F(t, y) = t - y\mathclose{\text{,}} and four steps of 0.5 lead from t=0t = 0 to t=2.t = 2\mathclose{\text{.}} Each row computes the slope at (tn,yn)(t_n, y_n) and takes a step along it, yn+1=yn+0.5×slope:y_{n+1} = y_n + 0.5 \times \text{slope}\mathclose{\text{:}}

nn tnt_n yny_n slope tn−ynt_n - y_n yn+1y_{n+1}
0 0 1 −1-1 0.5
1 0.5 0.5 0 0.5
2 1 0.5 0.5 0.75
3 1.5 0.75 0.75 1.125
4 2 1.125

So y(2)≈y4=1.125.y(2) \approx y_4 = 1.125\mathclose{\text{.}} The exact value is y(2)=2−1+2e−2=1+2e−2≈1.2707,y(2) = 2 - 1 + 2e^{-2} = 1 + 2e^{-2} \approx 1.2707\mathclose{\text{,}} so the error, the exact value minus the approximation, is about 0.146. Every approximation is too low. The reason is that the solution is concave up (y′′=2e−t>0;y'' = 2e^{-t} > 0\mathclose{\text{;}} Module 8), and a step along a tangent line of a curve that is concave up ends below the curve. Exercise 13.10 proves that the approximations stay below the solution at every step.

Euler's method for y' = t - y, y(0) = 1, on its direction field (light grey). With h = 0.5 (orange), the four steps of Example 13.6 end at 1.125; with h = 0.25 (green), eight steps end at 1.2002. The exact value is y(2) = 1 + 2e^{-2} approx 1.2707 (blue). Each step follows the slope at its starting point. Halving the step roughly halves the error at t = 2, from 0.146 to 0.070.
Figure 13.2

Euler’s method for y′=t−y,y' = t - y\mathclose{\text{,}} y(0)=1,y(0) = 1\mathclose{\text{,}} on its direction field (light grey). With h=0.5h = 0.5 (orange), the four steps of Example 13.6 end at 1.125; with h=0.25h = 0.25 (green), eight steps end at 1.2002. The exact value is y(2)=1+2e−2≈1.2707y(2) = 1 + 2e^{-2} \approx 1.2707 (blue). Each step follows the slope at its starting point. Halving the step roughly halves the error at t=2,t = 2\mathclose{\text{,}} from 0.146 to 0.070.

How the error depends on the step

For y′=y,y' = y\mathclose{\text{,}} y(0)=1,y(0) = 1\mathclose{\text{,}} whose solution is et,e^t\mathclose{\text{,}} Euler’s method is especially transparent. Each step computes yn+1=yn+h yn=(1+h) yn:y_{n+1} = y_n + h\,y_n = (1 + h)\,y_n\mathclose{\text{:}} it multiplies by 1+h.1 + h\mathclose{\text{.}} So yn=(1+h)n.y_n = (1 + h)^n\mathclose{\text{.}} Reaching t=1t = 1 takes n=1/hn = 1/h steps, so Euler’s approximation to y(1)=ey(1) = e is (1+h)1/h=(1+1n)n:(1 + h)^{1/h} = \big(1 + \tfrac1n\big)^n\mathclose{\text{:}} the compound interest of Module 6, with each step one compounding period. The table halves hh again and again; the error is e−(1+h)1/h:e - (1 + h)^{1/h}\mathclose{\text{:}}

hh(1+h)1/h(1 + h)^{1/h}error\text{error}error/h\text{error}/h
0.50.52.252.250.46830.46830.93660.9366
0.250.252.4412.4410.27690.27691.1081.108
0.1250.1252.5662.5660.15250.15251.2201.220
0.06250.06252.6382.6380.080350.080351.2861.286
0.031250.031252.6772.6770.041290.041291.3211.321
0.0010.0012.7172.7170.0013580.0013581.3581.358

Each halving of hh roughly halves the error, and the error divided by hh settles down, towards e/2≈1.359:e/2 \approx 1.359\mathclose{\text{:}} for small hh the error is about e2h.\tfrac{e}{2}h\mathclose{\text{.}}

Why proportional to h?h\mathclose{\text{?}} Each step follows a tangent line, and Section 7.2 stated (Module 15 proves it) that over a step of length hh the tangent line misses the curve by about h22y′′.\tfrac{h^2}{2}y''\mathclose{\text{.}} So each step makes a new error of order h2.h^2\mathclose{\text{.}} Reaching a fixed time TT takes (T−t0)/h(T - t_0)/h steps, and (T−t0)/h(T - t_0)/h errors of size about constant×h2\text{constant} \times h^2 add up to about a constant times h.h\mathclose{\text{.}} Errors made early on are also carried along by the later steps, which can magnify or shrink them; that changes the constant but not the power of h.h\mathclose{\text{.}} For y′=yy' = y on [0,1],[0, 1]\mathclose{\text{,}} the step at time tt makes an error of about h22et,\tfrac{h^2}{2}e^t\mathclose{\text{,}} which the equation magnifies by the factor e1−te^{1-t} by the time t=1t = 1 (solutions of y′=yy' = y spread apart like et).e^t\mathclose{\text{).}} So each step contributes about h22e,\tfrac{h^2}{2}e\mathclose{\text{,}} and the 1/h1/h steps add up to e2h:\tfrac{e}{2}h\mathclose{\text{:}} the constant in the table.

Key idea

Euler’s method has order 1: at a fixed time, its error is about a constant times h,h\mathclose{\text{,}} that is, O(h)O(h) in the notation of Section 4.7. Halving hh roughly halves the error and doubles the work; one more correct decimal costs about ten times as many steps.

Going deeperA bound for the error of Euler’s method

Suppose the solution yy of y′=F(t,y),y' = F(t, y)\mathclose{\text{,}} y(t0)=y0,y(t_0) = y_0\mathclose{\text{,}} satisfies ∣y′′∣≤M\abs{y''} \le M on [t0,T],[t_0, T]\mathclose{\text{,}} and that ∣Fy(t,y)∣≤L\abs{F_y(t, y)} \le L for t0≤t≤Tt_0 \le t \le T and every y,y\mathclose{\text{,}} with L>0.L > 0\mathclose{\text{.}} Then the errors en=y(tn)−yne_n = y(t_n) - y_n of Euler’s method satisfy, whenever tn≤T,t_n \le T\mathclose{\text{,}}

∣en∣≤Mh2L(eL(tn−t0)−1).\abs{e_n} \le \frac{Mh}{2L}\Big(e^{L(t_n - t_0)} - 1\Big).

The bound is proportional to h.h\mathclose{\text{.}} Here is why. By the error bound for linear approximation (Section 7.2; Module 15 proves it), y(tn+1)=y(tn)+h y′(tn)+τny(t_{n+1}) = y(t_n) + h\,y'(t_n) + \tau_n with ∣τn∣≤M2h2,\abs{\tau_n} \le \tfrac{M}{2}h^2\mathclose{\text{,}} and y′(tn)=F(tn,y(tn)).y'(t_n) = F\big(t_n, y(t_n)\big)\mathclose{\text{.}} Subtract yn+1=yn+h F(tn,yn):y_{n+1} = y_n + h\,F(t_n, y_n)\mathclose{\text{:}}

en+1=en+τn+h[F(tn,y(tn))−F(tn,yn)].\begin{aligned} e_{n+1} &= e_n + \tau_n \\ &\quad + h\Big[F\big(t_n, y(t_n)\big) - F(t_n, y_n)\Big]. \end{aligned}

By the Mean Value Theorem (Module 8), applied to F(tn,y)F(t_n, y) as a function of y,y\mathclose{\text{,}} the bracket is FyF_y at some point between yny_n and y(tn),y(t_n)\mathclose{\text{,}} times en;e_n\mathclose{\text{;}} so it is at most L∣en∣L\abs{e_n} in size, and

∣en+1∣≤(1+hL)∣en∣+M2h2.\abs{e_{n+1}} \le (1 + hL)\abs{e_n} + \tfrac{M}{2}h^2.

Start from e0=0e_0 = 0 and apply this nn times. With q=1+hL,q = 1 + hL\mathclose{\text{,}} and the sum 1+q+⋯+qn−1=qn−1q−11 + q + \dots + q^{n-1} = \dfrac{q^n - 1}{q - 1} (multiply out (q−1)(1+q+⋯+qn−1)(q - 1)(1 + q + \dots + q^{n-1}) to see it),

∣en∣≤M2h2 (1+hL)n−1hL=Mh2L((1+hL)n−1).\begin{aligned} \abs{e_n} &\le \frac{M}{2}h^2\,\frac{(1 + hL)^n - 1}{hL} \\ &= \frac{Mh}{2L}\Big((1 + hL)^n - 1\Big). \end{aligned}

Finally, 1+hL≤ehL,1 + hL \le e^{hL}\mathclose{\text{,}} because the graph of exe^x lies above its tangent line y=1+xy = 1 + x at 0 (it is concave up, Module 8). So (1+hL)n≤enhL=eL(tn−t0).(1 + hL)^n \le e^{nhL} = e^{L(t_n - t_0)}\mathclose{\text{.}}

The bound is often pessimistic. For Example 13.6, Fy=−1F_y = -1 gives L=1,L = 1\mathclose{\text{,}} and y′′=2e−t≤2y'' = 2e^{-t} \le 2 gives M=2;M = 2\mathclose{\text{;}} at t=2t = 2 the bound is (e2−1)h≈6.4h,(e^2 - 1)h \approx 6.4h\mathclose{\text{,}} while the actual error is about 0.27h.0.27h\mathclose{\text{.}} But it proves that the error is O(h).O(h)\mathclose{\text{.}}

Runge–Kutta methods

Euler’s method uses one slope per step, the slope at the start. Better methods sample the direction field at several points of each step and average. The most famous is the classical fourth-order Runge–Kutta method, called RK4:

k1=F(tn,yn),k2=F(tn+h2, yn+h2k1),k3=F(tn+h2, yn+h2k2),k4=F(tn+h, yn+h k3),yn+1=yn+h6(k1+2k2+2k3+k4).\begin{aligned} k_1 &= F(t_n, y_n), \\ k_2 &= F\big(t_n + \tfrac{h}{2},\ y_n + \tfrac{h}{2}k_1\big), \\ k_3 &= F\big(t_n + \tfrac{h}{2},\ y_n + \tfrac{h}{2}k_2\big), \\ k_4 &= F(t_n + h,\ y_n + h\,k_3), \\ y_{n+1} &= y_n + \tfrac{h}{6}\big(k_1 + 2k_2 + 2k_3 + k_4\big). \end{aligned}

k1k_1 is Euler’s slope at the start of the step; k2k_2 and k3k_3 are slopes at the middle of the step, at points reached with k1k_1 and then with k2;k_2\mathclose{\text{;}} k4k_4 is a slope at the end. When FF depends on tt only, so that the equation is y′=F(t)y' = F(t) and the answer is an integral, k2=k3k_2 = k_3 and the step is Simpson’s rule (Module 11) for ∫F(t) dt\int F(t)\,dt over the step. When FF is smooth, RK4’s error at a fixed time is O(h4):O(h^4)\mathclose{\text{:}} halving hh divides it by about 16. Methods of this family, with a step size that the program adjusts as it goes, are standard in numerical software. The solve_ivp function of SciPy, a Python library that this series does not install, uses one unless told otherwise: RK45, a Runge–Kutta method of order 5(4). Each of its steps makes two estimates, of orders 5 and 4, and their difference serves to adapt the step size to an error tolerance.

Compute itEuler’s method and RK4 in Python

A function for Euler’s method, and its errors for y′=t−y,y' = t - y\mathclose{\text{,}} y(0)=1y(0) = 1 at t=2t = 2 as hh halves:

Python
import math

def euler(F, t, y, h, n):
    """n steps of Euler's method from (t, y) with step h; returns the last y."""
    for _ in range(n):
        y, t = y + h*F(t, y), t + h
    return y

F = lambda t, y: t - y                 # y' = t - y, y(0) = 1
exact = 1 + 2*math.exp(-2)             # y(2), from Example 13.1
for n in [10, 20, 40, 80]:
    h = 2/n
    err = exact - euler(F, 0, 1, h, n)
    print(f"h = {h:<6} error = {err:.6f}   error/h = {err/h:.4f}")
Output
h = 0.2    error = 0.055922   error/h = 0.2796
h = 0.1    error = 0.027517   error/h = 0.2752
h = 0.05   error = 0.013646   error/h = 0.2729
h = 0.025  error = 0.006795   error/h = 0.2718

Halving hh halves the error, and the error divided by hh settles near 0.27. (y, t = y + h*F(t, y), t + h updates both variables at once, using the old values on the right.) Now RK4, at the same step sizes:

Python
def rk4(F, t, y, h, n):
    """n steps of the classical Runge-Kutta method; returns the last y."""
    for _ in range(n):
        k1 = F(t, y)
        k2 = F(t + h/2, y + h/2*k1)
        k3 = F(t + h/2, y + h/2*k2)
        k4 = F(t + h, y + h*k3)
        y, t = y + h/6*(k1 + 2*k2 + 2*k3 + k4), t + h
    return y

for n in [10, 20, 40]:
    h = 2/n
    e1, e4 = exact - euler(F, 0, 1, h, n), exact - rk4(F, 0, 1, h, n)
    print(f"h = {h:<5} Euler error = {e1:.2e}   RK4 error = {e4:.2e}")
Output
h = 0.2   Euler error = 5.59e-02   RK4 error = -8.53e-06
h = 0.1   Euler error = 2.75e-02   RK4 error = -4.90e-07
h = 0.05  Euler error = 1.36e-02   RK4 error = -2.94e-08

RK4’s errors are negative because it overshoots slightly, and each halving of hh divides them by about 16 (from 8.5×10−68.5 \times 10^{-6} to 4.9×10−74.9 \times 10^{-7} to 2.9×10−8).2.9 \times 10^{-8}\mathclose{\text{).}} RK4 costs four evaluations of FF per step, so compare equal work: RK4 with h=0.2h = 0.2 evaluates FF 40 times and is off by about 10−5;10^{-5}\mathclose{\text{;}} Euler’s method with h=0.05h = 0.05 also evaluates FF 40 times, and is off by about 10−2.10^{-2}\mathclose{\text{.}}

Watch out

A step that is too large can make Euler’s method useless, not merely inaccurate. For y′=−20y,y' = -20y\mathclose{\text{,}} y(0)=1,y(0) = 1\mathclose{\text{,}} the solution e−20te^{-20t} decays fast. Euler’s method computes yn+1=yn−20h yn=(1−20h) yn,y_{n+1} = y_n - 20h\,y_n = (1 - 20h)\,y_n\mathclose{\text{,}} so yn=(1−20h)n.y_n = (1 - 20h)^n\mathclose{\text{.}} With h=0.15h = 0.15 the factor is −2,-2\mathclose{\text{,}} and the approximations 1,−2,4,−8,…1, -2, 4, -8, \dots swing ever more wildly. They decay, as the solution does, only if ∣1−20h∣<1,\abs{1 - 20h} < 1\mathclose{\text{,}} that is, for h<0.1.h < 0.1\mathclose{\text{.}} Equations with such fast-decaying parts are called stiff, and numerical software has special methods for them.

Try it

Choose an equation, then click the plot, or use the t0t_0 and y0y_0 sliders, to choose a starting point. The blue curve is the solution through it, computed accurately with RK4; the orange dots are Euler’s method with step h,h\mathclose{\text{,}} up to the end time TT (dashed line), and the readout compares the two at T.T\mathclose{\text{.}} With y′=t−yy' = t - y from (0,1)(0, 1) and h=0.5h = 0.5 you see Example 13.6. Move the hh slider one notch at a time: each notch halves h,h\mathclose{\text{,}} the error roughly halves too, and the error divided by hh settles down. Start on the line y=t−1:y = t - 1\mathclose{\text{:}} why is Euler’s method exact there? Then try y′=yy' = y from (0,1),(0, 1)\mathclose{\text{,}} which gives the table above, the logistic equation y′=y(1−y)y' = y(1 - y) from several heights, and y′=t−y2y' = t - y^2 from points below the tt-axis.

5

Separable equations

Euler’s method gives numbers. Some equations can be solved exactly, with a formula, and the most common kind is the following.

Definition 13.6Separable equation

A first-order differential equation is separable if it can be written as

y′=g(t) h(y),y' = g(t)\,h(y),

a function of tt times a function of y.y\mathclose{\text{.}}

y′=ky,y' = ky\mathclose{\text{,}} y′=2ty2,y' = 2ty^2\mathclose{\text{,}} the cooling equation T′=−k(T−Ts)T' = -k(T - T_s) and the equation of the mixing tank are separable. y′=t−yy' = t - y is not: t−yt - y is not a product of a function of tt and a function of yy (Section 13.7 solves it another way).

The method is quickest in Leibniz notation. Write y′y' as dydt,\dfrac{dy}{dt}\mathclose{\text{,}} move everything that contains yy to one side and everything that contains tt to the other, as if dydy and dtdt were numbers, and integrate both sides:

dydt=g(t)h(y),dyh(y)=g(t) dt,∫dyh(y)=∫g(t) dt.\begin{aligned} \frac{dy}{dt} &= g(t)h(y), \\ \frac{dy}{h(y)} &= g(t)\,dt, \\ \int\frac{dy}{h(y)} &= \int g(t)\,dt. \end{aligned}

Nothing so far allows you to split dydt\dfrac{dy}{dt} like a fraction: it is a single symbol for a limit (Section 4.2). The chain rule is what makes the result right.

Theorem 13.3Separation of variables

Let gg be continuous on an open interval I,I\mathclose{\text{,}} and let hh be continuous and never 0 on an open interval J.J\mathclose{\text{.}} Let GG be an antiderivative of gg on I,I\mathclose{\text{,}} and HH an antiderivative of 1/h1/h on J.J\mathclose{\text{.}} A differentiable function yy on II with values in JJ is a solution of y′=g(t)h(y)y' = g(t)h(y) exactly when, for some constant C,C\mathclose{\text{,}}

H(y(t))=G(t)+Cfor every t in I.H\big(y(t)\big) = G(t) + C \quad\text{for every } t \text{ in } I.
Proof

By the chain rule, the derivative of H(y(t))H\big(y(t)\big) is H′(y(t)) y′(t)=y′(t)h(y(t)).H'\big(y(t)\big)\,y'(t) = \dfrac{y'(t)}{h\big(y(t)\big)}\mathclose{\text{.}} Since h(y(t))≠0,h\big(y(t)\big) \ne 0\mathclose{\text{,}} the equation y′=g(t)h(y)y' = g(t)h(y) holds at tt exactly when y′(t)h(y(t))=g(t),\dfrac{y'(t)}{h(y(t))} = g(t)\mathclose{\text{,}} that is, when

ddt[H(y(t))−G(t)]=0.\frac{d}{dt}\Big[H\big(y(t)\big) - G(t)\Big] = 0.

A function whose derivative is 0 at every point of an interval is constant there (a consequence of the Mean Value Theorem, Module 8), and a constant has derivative 0. So yy is a solution on II exactly when H(y(t))−G(t)H\big(y(t)\big) - G(t) is a constant C.C\mathclose{\text{.}}

∎
Key idea

To solve y′=g(t)h(y):y' = g(t)h(y)\mathclose{\text{:}}

  1. Separate: dyh(y)=g(t) dt,\dfrac{dy}{h(y)} = g(t)\,dt\mathclose{\text{,}} where h(y)≠0.h(y) \ne 0\mathclose{\text{.}}
  2. Integrate both sides; one constant C,C\mathclose{\text{,}} on one side, is enough.
  3. Solve for yy if you can, and use the initial condition to find C.C\mathclose{\text{.}}
  4. Look for constant solutions y=y∗y = y^* with h(y∗)=0:h(y^*) = 0\mathclose{\text{:}} they are solutions, and step 1 lost them.

When gg is continuous and hh has a continuous derivative, these steps find every solution. Theorem 13.1 applies, since F=g(t)h(y)F = g(t)h(y) and Fy=g(t)h′(y)F_y = g(t)h'(y) are continuous: a solution that took a value y∗y^* with h(y∗)=0h(y^*) = 0 at one time would be the constant solution y∗.y^*\mathclose{\text{.}} So every other solution keeps h(y)≠0,h(y) \ne 0\mathclose{\text{,}} and dividing by h(y)h(y) is allowed for it. Without the condition on h′h' this can fail: y=t3y = t^3 solves y′=3y2/3y' = 3y^{2/3} (Section 13.1) and passes through 0, a zero of h(y)=3y2/3.h(y) = 3y^{2/3}\mathclose{\text{.}}

Example 13.7A solution that blows up✓ Checked

Solve y′=2ty2y' = 2ty^2 with (a) y(0)=1,y(0) = 1\mathclose{\text{,}} (b) y(0)=−1,y(0) = -1\mathclose{\text{,}} (c) y(0)=0.y(0) = 0\mathclose{\text{.}}

Here g(t)=2tg(t) = 2t and h(y)=y2,h(y) = y^2\mathclose{\text{,}} which has a continuous derivative, so, by the paragraph above, the only solution that is ever 0 is the constant solution y=0.y = 0\mathclose{\text{.}} The solutions of (a) and (b) are never 0, so you may divide by y2.y^2\mathclose{\text{.}} Separate and integrate:

∫dyy2=∫2t dt,−1y=t2+C,y=−1t2+C.\begin{aligned} \int \frac{dy}{y^2} &= \int 2t\,dt, \\ -\frac1y &= t^2 + C, \\ y &= -\frac{1}{t^2 + C}. \end{aligned}

(a) y(0)=−1C=1y(0) = -\dfrac1C = 1 gives C=−1,C = -1\mathclose{\text{,}} so y=11−t2.y = \dfrac{1}{1 - t^2}\mathclose{\text{.}} The formula makes sense for every t≠±1,t \ne \pm1\mathclose{\text{,}} but a solution lives on an interval, and the one containing t=0t = 0 is (−1,1).(-1, 1)\mathclose{\text{.}} As tt approaches 1 or −1,-1\mathclose{\text{,}} yy grows without bound: the solution blows up (Figure 13.3). The parts of the graph with ∣t∣>1\abs{t} > 1 belong to other solutions of the equation, not to this one: nothing connects them to y(0)=1.y(0) = 1\mathclose{\text{.}}

(b) y(0)=−1C=−1y(0) = -\dfrac1C = -1 gives C=1,C = 1\mathclose{\text{,}} so y=−11+t2,y = -\dfrac{1}{1 + t^2}\mathclose{\text{,}} defined for every t.t\mathclose{\text{.}}

(c) No constant CC gives y(0)=0,y(0) = 0\mathclose{\text{,}} because −1t2+C-\dfrac{1}{t^2 + C} is never 0. Dividing by y2y^2 assumed that y≠0.y \ne 0\mathclose{\text{.}} The constant function y=0y = 0 satisfies y′=0=2t⋅02,y' = 0 = 2t \cdot 0^2\mathclose{\text{,}} so it is a solution: the one the method lost. By Theorem 13.1 (F=2ty2F = 2ty^2 and Fy=4tyF_y = 4ty are continuous everywhere) it is the only solution with y(0)=0.y(0) = 0\mathclose{\text{.}}

Solutions of y' = 2ty^2 (Example 13.7) on its direction field. The solution with y(0) = 1, y = 1/(1 - t^2) (dark blue), exists only for -1 < t < 1; the dotted curves outside belong to other solutions. The solution with y(0) = tfrac14, y = 1/(4 - t^2), lasts until t = pm2; the solution with y(0) = -1 (orange) exists for every t. The constant solution y = 0 (green) is the one that dividing by y^2 loses.
Figure 13.3

Solutions of y′=2ty2y' = 2ty^2 (Example 13.7) on its direction field. The solution with y(0)=1,y(0) = 1\mathclose{\text{,}} y=1/(1−t2)y = 1/(1 - t^2) (dark blue), exists only for −1<t<1;-1 < t < 1\mathclose{\text{;}} the dotted curves outside belong to other solutions. The solution with y(0)=14,y(0) = \tfrac14\mathclose{\text{,}} y=1/(4−t2),y = 1/(4 - t^2)\mathclose{\text{,}} lasts until t=±2;t = \pm2\mathclose{\text{;}} the solution with y(0)=−1y(0) = -1 (orange) exists for every t.t\mathclose{\text{.}} The constant solution y=0y = 0 (green) is the one that dividing by y2y^2 loses.

Watch out

Two slips with separable equations. First, the constant: from ln⁡∣y∣=kt+C,\ln\abs{y} = kt + C\mathclose{\text{,}} the next step is ∣y∣=eCekt,\abs{y} = e^{C}e^{kt}\mathclose{\text{,}} not y=ekt+C;y = e^{kt} + C\mathclose{\text{;}} a constant added before you exponentiate becomes a factor afterwards. Second, dividing by h(y)h(y) loses the solutions where h(y)=0:h(y) = 0\mathclose{\text{:}} look for them every time.

Growth and decay

Module 6 checked that CektCe^{kt} solves y′=ky,y' = ky\mathclose{\text{,}} and promised that there are no other solutions. Separation finds the solutions that are never 0: ∫dyy=∫k dt\displaystyle\int\frac{dy}{y} = \int k\,dt gives ln⁡∣y∣=kt+C,\ln\abs{y} = kt + C\mathclose{\text{,}} so ∣y∣=eCekt\abs{y} = e^Ce^{kt} and y=Aekty = Ae^{kt} with A=±eC,A = \pm e^C\mathclose{\text{,}} a constant that is not 0; the lost solution y=0y = 0 is the case A=0.A = 0\mathclose{\text{.}} But could a solution be 0 at some times and not at others, so that Theorem 13.3 does not apply to it on a whole interval? Theorem 13.1 rules that out, as it does for every separable equation with a continuous h′.h'\mathclose{\text{.}} The next theorem proves it directly, with an argument that never divides by yy and does not need Theorem 13.1, which this series does not prove.

Theorem 13.4Exponential growth and decay

Let kk be a constant and II an open interval containing t0.t_0\mathclose{\text{.}} A differentiable function yy satisfies y′=kyy' = ky on II exactly when

y(t)=y(t0) ek(t−t0)for every t in I.y(t) = y(t_0)\,e^{k(t - t_0)} \quad\text{for every } t \text{ in } I.
Proof

If y(t)=y(t0)ek(t−t0),y(t) = y(t_0)e^{k(t - t_0)}\mathclose{\text{,}} then y′=kyy' = ky by the chain rule. Conversely, suppose that y′=kyy' = ky on I,I\mathclose{\text{,}} and let w(t)=y(t)e−kt.w(t) = y(t)e^{-kt}\mathclose{\text{.}} By the product rule,

w′=y′e−kt−k y e−kt=(y′−ky) e−kt=0\begin{aligned} w' &= y'e^{-kt} - k\,y\,e^{-kt} \\ &= (y' - ky)\,e^{-kt} = 0 \end{aligned}

on I,I\mathclose{\text{,}} so ww is constant on II (Module 8): w(t)=w(t0),w(t) = w(t_0)\mathclose{\text{,}} that is, y(t)e−kt=y(t0)e−kt0.y(t)e^{-kt} = y(t_0)e^{-kt_0}\mathclose{\text{.}} Multiply both sides by ekt.e^{kt}\mathclose{\text{.}}

∎

So a quantity whose rate of change is kk times its size is y(t0)ek(t−t0),y(t_0)e^{k(t - t_0)}\mathclose{\text{,}} and nothing else: it grows exponentially if k>0k > 0 and decays if k<0,k < 0\mathclose{\text{,}} with doubling time or half-life ln⁡2/∣k∣\ln 2/\abs{k} (Module 6).

Newton’s law of cooling

The cooling equation T′=−k(T−Ts)T' = -k(T - T_s) becomes the decay equation if you measure temperature from Ts.T_s\mathclose{\text{.}} Put u=T−Ts;u = T - T_s\mathclose{\text{;}} since TsT_s is constant, u′=T′=−ku.u' = T' = -ku\mathclose{\text{.}} By Theorem 13.4, u=u(0)e−kt,u = u(0)e^{-kt}\mathclose{\text{,}} that is,

T(t)=Ts+(T(0)−Ts)e−kt.T(t) = T_s + \big(T(0) - T_s\big)e^{-kt}.

The difference from the surroundings decays exponentially: the temperature approaches Ts,T_s\mathclose{\text{,}} a stable equilibrium, and never quite reaches it. The same shift solves every equation of the form y′=−k(y−A),y' = -k(y - A)\mathclose{\text{,}} with constants kk and A:A\mathclose{\text{:}} the falling body, v′=9.8−0.2v=−0.2(v−49),v' = 9.8 - 0.2v = -0.2(v - 49)\mathclose{\text{,}} and the mixing tank, y′=0.6−0.03y=−0.03(y−20),y' = 0.6 - 0.03y = -0.03(y - 20)\mathclose{\text{,}} are two more (Exercise 13.6).

Key idea

For constants k>0k > 0 and A,A\mathclose{\text{,}} the solution of y′=−k(y−A)y' = -k(y - A) is y=A+(y(0)−A)e−kt.y = A + \big(y(0) - A\big)e^{-kt}\mathclose{\text{.}} It approaches the equilibrium AA exponentially; in each time 1/k,1/k\mathclose{\text{,}} called the time constant, the distance from AA shrinks by the factor e.e\mathclose{\text{.}}

Example 13.8A cooling cup of tea✓ Checked

Suppose a cup of tea at 90 °C is left in a room at 20 °C, and after 5 minutes it is at 70 °C. Assuming Newton’s law of cooling, find k,k\mathclose{\text{,}} the temperature after 15 minutes, and when the tea reaches 40 °C.

By the formula, T(t)=20+70e−kt.T(t) = 20 + 70e^{-kt}\mathclose{\text{.}} At t=5:t = 5\mathclose{\text{:}} 70=20+70e−5k,70 = 20 + 70e^{-5k}\mathclose{\text{,}} so e−5k=5070=57e^{-5k} = \tfrac{50}{70} = \tfrac57 and

k=15ln⁡75≈0.0673 per minute.k = \frac{1}{5}\ln\frac75 \approx 0.0673 \text{ per minute}.

After 15 minutes, e−15k=(e−5k)3=(57)3,e^{-15k} = \big(e^{-5k}\big)^3 = \big(\tfrac57\big)^3\mathclose{\text{,}} so T(15)=20+70⋅125343≈45.5T(15) = 20 + 70 \cdot \tfrac{125}{343} \approx 45.5 °C. For 40 °C, solve 20+70e−kt=40:20 + 70e^{-kt} = 40\mathclose{\text{:}} e−kt=27,e^{-kt} = \tfrac27\mathclose{\text{,}} so

t=ln⁡(7/2)k=5ln⁡3.5ln⁡1.4≈18.6 minutes.t = \frac{\ln(7/2)}{k} = \frac{5\ln 3.5}{\ln 1.4} \approx 18.6 \text{ minutes}.

The first 20 degrees took 5 minutes; the next 30 take about 13.6 more. The closer the tea is to room temperature, the more slowly it cools.

6

The logistic equation

Exponential growth cannot last. A population that grows at the continuous rate k=0.05k = 0.05 per year, 5% a year, multiplies by e0.05⋅200=e10≈22,000e^{0.05 \cdot 200} = e^{10} \approx 22{,}000 in two centuries; long before that, food and space run short and growth slows. The simplest model of the slowdown starts from the per-capita growth rate y′/y,y'/y\mathclose{\text{,}} which is the constant kk in exponential growth, and lets it fall in a straight line as the population grows: from a value rr when yy is small, to 0 when yy reaches a level K,K\mathclose{\text{,}} the carrying capacity. So y′/y=r(1−y/K),y'/y = r(1 - y/K)\mathclose{\text{,}} that is,

y′=r y(1−yK),y' = r\,y\Big(1 - \frac{y}{K}\Big),

with constants r>0,r > 0\mathclose{\text{,}} measured per unit of time like k,k\mathclose{\text{,}} and K>0,K > 0\mathclose{\text{,}} in the units of yy (a number of animals, say). This is the logistic equation.

It is autonomous. Its right side f(y)=ry(1−y/K)f(y) = ry(1 - y/K) is 0 at y=0y = 0 and y=K,y = K\mathclose{\text{,}} and f′(y)=r−2ry/K,f'(y) = r - 2ry/K\mathclose{\text{,}} so f′(0)=r>0f'(0) = r > 0 and f′(K)=−r<0:f'(K) = -r < 0\mathclose{\text{:}} by Theorem 13.2, 0 is unstable and KK is stable. Between 0 and K,K\mathclose{\text{,}} f>0f > 0 and solutions rise towards K;K\mathclose{\text{;}} above K,K\mathclose{\text{,}} f<0f < 0 and they fall towards it. A small population grows almost exponentially at first, since y′≈ryy' \approx ry when yy is small compared with K;K\mathclose{\text{;}} every positive population approaches K.K\mathclose{\text{.}}

To solve it, take 0<y0<K,0 < y_0 < K\mathclose{\text{,}} where y0=y(0);y_0 = y(0)\mathclose{\text{;}} then 0<y<K0 < y < K for all tt (the solution cannot cross the equilibria). Separate:

∫dyy(1−y/K)=∫r dt.\int\frac{dy}{y(1 - y/K)} = \int r\,dt.

By partial fractions (Module 11),

1y(1−y/K)=Ky(K−y)=1y+1K−y,\frac{1}{y(1 - y/K)} = \frac{K}{y(K - y)} = \frac{1}{y} + \frac{1}{K - y},

and since ∫dyK−y=−ln⁡∣K−y∣,\displaystyle\int\frac{dy}{K - y} = -\ln\abs{K - y}\mathclose{\text{,}} the left side is ln⁡y−ln⁡(K−y)=ln⁡yK−y\ln y - \ln(K - y) = \ln\dfrac{y}{K - y} (both yy and K−yK - y are positive). So ln⁡yK−y=rt+C,\ln\dfrac{y}{K - y} = rt + C\mathclose{\text{,}} and

yK−y=Aert,A=eC=y0K−y0,\frac{y}{K - y} = Ae^{rt}, \qquad A = e^C = \frac{y_0}{K - y_0},

the value of AA coming from t=0.t = 0\mathclose{\text{.}} Solve for y:y\mathclose{\text{:}} y=Aert(K−y),y = Ae^{rt}(K - y)\mathclose{\text{,}} so y(1+Aert)=KAert;y\big(1 + Ae^{rt}\big) = KAe^{rt}\mathclose{\text{;}} divide by 1+Aert,1 + Ae^{rt}\mathclose{\text{,}} and then divide the top and the bottom by Aert:Ae^{rt}\mathclose{\text{:}}

y(t)=K1+K−y0y0 e−rt.y(t) = \frac{K}{1 + \dfrac{K - y_0}{y_0}\,e^{-rt}}.

Substituting into the equation confirms it, and shows that the same formula is the solution for every y0>0,y_0 > 0\mathclose{\text{,}} also above K;K\mathclose{\text{;}} it is defined for all t≥0.t \ge 0\mathclose{\text{.}} Its graph, from a small y0,y_0\mathclose{\text{,}} is the S-shaped logistic curve (Figure 13.4).

The fastest growth. The rate y′=ry(1−y/K)y' = ry(1 - y/K) is a downward parabola in y,y\mathclose{\text{,}} largest at y=K/2,y = K/2\mathclose{\text{,}} where it is rK/4.rK/4\mathclose{\text{.}} By the chain rule y′′=f′(y) y′=r(1−2yK)y′,y'' = f'(y)\,y' = r\big(1 - \tfrac{2y}{K}\big)y'\mathclose{\text{,}} which changes sign as yy passes K/2:K/2\mathclose{\text{:}} a logistic curve that starts below K/2K/2 has its inflection point at half the carrying capacity, at the time t∗t^* with y(t∗)=K/2,y(t^*) = K/2\mathclose{\text{,}} that is, K−y0y0e−rt∗=1,\dfrac{K - y_0}{y_0}e^{-rt^*} = 1\mathclose{\text{,}} or

t∗=1rln⁡K−y0y0.t^* = \frac1r\ln\frac{K - y_0}{y_0}.
Example 13.9Fish in a lake✓ Checked

Suppose a lake can support K=10,000K = 10{,}000 fish of some species, 1000 are introduced, and the population follows the logistic equation with r=0.5r = 0.5 per year. Find the population after 10 years, when it reaches half the carrying capacity, and its fastest rate of growth.

Here K−y0y0=90001000=9,\dfrac{K - y_0}{y_0} = \dfrac{9000}{1000} = 9\mathclose{\text{,}} so

y(t)=10,0001+9e−0.5t.y(t) = \frac{10{,}000}{1 + 9e^{-0.5t}}.

After 10 years, y(10)=10,0001+9e−5≈9428y(10) = \dfrac{10{,}000}{1 + 9e^{-5}} \approx 9428 fish. Half the capacity is reached when 9e−0.5t=1,9e^{-0.5t} = 1\mathclose{\text{,}} at t=2ln⁡9≈4.39t = 2\ln 9 \approx 4.39 years, and then the population grows fastest, at rK/4=0.5⋅10,000/4=1250rK/4 = 0.5 \cdot 10{,}000/4 = 1250 fish per year.

Logistic growth y' = 0.5y(1 - y/10{,}000), with y in thousands. From y(0) = 1000 (dark blue, Example 13.9) the population follows an S-curve, with its inflection point at y = K/2 after 2ln 9 approx 4.39 years. From 100 the S-curve comes later; from 6000, above K/2, the curve has no inflection; from 15,000, above K, the population falls towards K.
Figure 13.4

Logistic growth y′=0.5y(1−y/10,000),y' = 0.5y(1 - y/10{,}000)\mathclose{\text{,}} with yy in thousands. From y(0)=1000y(0) = 1000 (dark blue, Example 13.9) the population follows an S-curve, with its inflection point at y=K/2y = K/2 after 2ln⁡9≈4.392\ln 9 \approx 4.39 years. From 100 the S-curve comes later; from 6000, above K/2,K/2\mathclose{\text{,}} the curve has no inflection; from 15,000, above K,K\mathclose{\text{,}} the population falls towards K.K\mathclose{\text{.}}

In machine learning, the logistic curve with r=1,r = 1\mathclose{\text{,}} K=1K = 1 and y(0)=12,y(0) = \tfrac12\mathclose{\text{,}} the function σ(t)=11+e−t\sigma(t) = \dfrac{1}{1 + e^{-t}} (read “sigma of t”), is called the sigmoid. Because it solves y′=y(1−y),y' = y(1 - y)\mathclose{\text{,}} its derivative is σ′=σ(1−σ):\sigma' = \sigma(1 - \sigma)\mathclose{\text{:}} once a program has computed σ(t),\sigma(t)\mathclose{\text{,}} the derivative costs one subtraction and one multiplication.

Watch out

Watch the sign in ∫dyK−y=−ln⁡∣K−y∣+C:\displaystyle\int\frac{dy}{K - y} = -\ln\abs{K - y} + C\mathclose{\text{:}} by the chain rule, the derivative of ln⁡∣K−y∣\ln\abs{K - y} is −1K−y.-\dfrac{1}{K - y}\mathclose{\text{.}} With the wrong sign you get ln⁡(y(K−y))=rt+C,\ln\big(y(K - y)\big) = rt + C\mathclose{\text{,}} whose solutions do not level off at K;K\mathclose{\text{;}} the direction field, where every solution approaches K,K\mathclose{\text{,}} catches the mistake.

7

First-order linear equations

Example 13.1 checked that y=t−1+Ce−ty = t - 1 + Ce^{-t} solves y′=t−y.y' = t - y\mathclose{\text{.}} But how would you find that formula, and how do you know that there are no other solutions? The equation is not separable. It belongs to another family, with a method of its own.

Definition 13.7First-order linear equation

A first-order differential equation is linear if it can be written in the standard form

y′+p(t) y=q(t),y' + p(t)\,y = q(t),

where pp and qq are functions of tt alone.

“Linear” refers to yy and y′:y'\mathclose{\text{:}} each appears to the first power, not multiplied by the other and not inside another function. y′=t−yy' = t - y is linear, with standard form y′+y=t,y' + y = t\mathclose{\text{,}} so p(t)=1p(t) = 1 and q(t)=t;q(t) = t\mathclose{\text{;}} so are the equations of cooling, of the falling body and of the mixing tank. y′=2ty2y' = 2ty^2 and the logistic equation are not.

The left side y′+pyy' + py looks almost like the result of the product rule. Multiply the equation by a function μ(t)\mu(t) (read “mu of t”), still to be chosen: μy′+μp y=μq.\mu y' + \mu p\,y = \mu q\mathclose{\text{.}} If μ′=μp,\mu' = \mu p\mathclose{\text{,}} the left side is exactly (μy)′=μy′+μ′y.(\mu y)' = \mu y' + \mu' y\mathclose{\text{.}} The function μ=eP(t),\mu = e^{P(t)}\mathclose{\text{,}} with PP an antiderivative of p,p\mathclose{\text{,}} does this: by the chain rule, μ′=ePP′=μp.\mu' = e^{P}P' = \mu p\mathclose{\text{.}} Then the equation says (μy)′=μq,(\mu y)' = \mu q\mathclose{\text{,}} and integrating gives μy.\mu y\mathclose{\text{.}}

Theorem 13.5First-order linear equations

Let pp and qq be continuous on an open interval I.I\mathclose{\text{.}} Let PP be an antiderivative of pp on I,I\mathclose{\text{,}} let μ=eP,\mu = e^{P}\mathclose{\text{,}} the integrating factor, and let RR be an antiderivative of μq\mu q on I.I\mathclose{\text{.}} Then the solutions of y′+p(t)y=q(t)y' + p(t)y = q(t) on II are exactly the functions

y=R(t)+Cμ(t),C a constant.y = \frac{R(t) + C}{\mu(t)}, \qquad C \text{ a constant}.

For every t0t_0 in II and every number y0,y_0\mathclose{\text{,}} exactly one of them satisfies y(t0)=y0,y(t_0) = y_0\mathclose{\text{,}} and it is defined on the whole of I.I\mathclose{\text{.}}

Proof

The antiderivatives PP and RR exist because pp and μq\mu q are continuous (the Fundamental Theorem of Calculus, Module 10). The function μ\mu is positive, and μ′=pμ\mu' = p\mu by the chain rule. For any differentiable yy on I,I\mathclose{\text{,}} the product rule gives (μy)′=μy′+pμy=μ(y′+py).(\mu y)' = \mu y' + p\mu y = \mu(y' + py)\mathclose{\text{.}} Since μ≠0,\mu \ne 0\mathclose{\text{,}} yy is a solution on II exactly when (μy)′=μq=R′,(\mu y)' = \mu q = R'\mathclose{\text{,}} that is, when (μy−R)′=0,(\mu y - R)' = 0\mathclose{\text{,}} that is, when μy−R\mu y - R is a constant CC on II (Module 8). This is the formula. The condition y(t0)=y0y(t_0) = y_0 holds for exactly one constant, C=μ(t0)y0−R(t0).C = \mu(t_0)y_0 - R(t_0)\mathclose{\text{.}}

∎

Compare Theorem 13.1: for a linear equation, the solution exists on the whole interval where pp and qq are continuous. A linear equation cannot blow up the way y=1/(1−t2)y = 1/(1 - t^2) did.

Key idea

To solve y′+p(t)y=q(t):y' + p(t)y = q(t)\mathclose{\text{:}}

  1. Put the equation in standard form, with y′y' alone (coefficient 1).
  2. Compute μ=e∫p dt;\mu = e^{\int p\,dt}\mathclose{\text{;}} any antiderivative will do, so leave out the constant.
  3. Multiply the equation by μ:\mu\mathclose{\text{:}} the left side is (μy)′.(\mu y)'\mathclose{\text{.}}
  4. Integrate both sides, with a constant C,C\mathclose{\text{,}} and divide by μ.\mu\mathclose{\text{.}}
Example 13.10Solving y′=t−yy' = t - y✓ Checked

Find the general solution of y′=t−y.y' = t - y\mathclose{\text{.}}

In standard form, y′+y=t,y' + y = t\mathclose{\text{,}} so p=1p = 1 and μ=et.\mu = e^{t}\mathclose{\text{.}} Multiply by et,e^t\mathclose{\text{,}} and the left side becomes the derivative of a product:

ety′+ety=tet,(ety)′=tet.\begin{aligned} e^t y' + e^t y &= te^t, \\ \big(e^t y\big)' &= te^t. \end{aligned}

Integrate by parts (Module 11), with u=tu = t and dv=et dt:dv = e^t\,dt\mathclose{\text{:}} ∫tet dt=tet−∫et dt=(t−1)et+C.\displaystyle\int te^t\,dt = te^t - \int e^t\,dt = (t - 1)e^t + C\mathclose{\text{.}} So ety=(t−1)et+C,e^t y = (t - 1)e^t + C\mathclose{\text{,}} and

y=t−1+Ce−t.y = t - 1 + Ce^{-t}.

This is the family of Example 13.1, found rather than guessed, and by Theorem 13.5 there are no other solutions.

Example 13.11A tank that fills up✓ Checked

The tank of Example 13.3 starts again, now with 100 litres of pure water and room for 200 litres. Salt water with 0.2 kg of salt per litre flows in at 3 litres per minute, but the mixture flows out at only 2 litres per minute. How much salt is in the tank when it becomes full?

The volume grows by 1 litre per minute, so after tt minutes it is 100+t100 + t litres, and the tank is full at t=100.t = 100\mathclose{\text{.}} The concentration is y100+t,\dfrac{y}{100 + t}\mathclose{\text{,}} so salt leaves at 2y100+t\dfrac{2y}{100 + t} kg per minute, and

y′=0.6−2y100+t,y(0)=0.y' = 0.6 - \frac{2y}{100 + t}, \qquad y(0) = 0.

This equation is linear but not autonomous. In standard form, y′+2100+t y=0.6.y' + \dfrac{2}{100 + t}\,y = 0.6\mathclose{\text{.}} For t>−100,t > -100\mathclose{\text{,}} an antiderivative of pp is 2ln⁡(100+t),2\ln(100 + t)\mathclose{\text{,}} so

μ=e2ln⁡(100+t)=(100+t)2.\mu = e^{2\ln(100 + t)} = (100 + t)^2.

Then ((100+t)2y)′=0.6(100+t)2,\big((100 + t)^2y\big)' = 0.6(100 + t)^2\mathclose{\text{,}} and integrating, (100+t)2y=0.2(100+t)3+C.(100 + t)^2y = 0.2(100 + t)^3 + C\mathclose{\text{.}} At t=0:t = 0\mathclose{\text{:}} 0=0.2⋅106+C,0 = 0.2 \cdot 10^6 + C\mathclose{\text{,}} so C=−200,000C = -200{,}000 and

y=0.2(100+t)−200,000(100+t)2.y = 0.2(100 + t) - \frac{200{,}000}{(100 + t)^2}.

When the tank is full, y(100)=40−200,00040,000=35y(100) = 40 - \dfrac{200{,}000}{40{,}000} = 35 kg of salt, a concentration of 35/200=0.17535/200 = 0.175 kg per litre, still below the inflow’s 0.2.

Example 13.12Charging a capacitor✓ Checked

In an electric circuit, a resistor of RR ohms and a capacitor of CC farads are connected in series to a battery of constant voltage EE volts. The voltages across the resistor, RiRi with current i=q′,i = q'\mathclose{\text{,}} and across the capacitor, q/Cq/C with charge qq on the capacitor, add up to the battery’s voltage:

Rq′+qC=E.Rq' + \frac{q}{C} = E.

Suppose R=10,000R = 10{,}000 ohms, C=100C = 100 microfarads =10−4= 10^{-4} farads, E=5E = 5 volts, and the capacitor starts uncharged. Find q(t)q(t) and the voltage across the capacitor.

Divide by R:R\mathclose{\text{:}} q′+qRC=ER.q' + \dfrac{q}{RC} = \dfrac{E}{R}\mathclose{\text{.}} Here RC=104⋅10−4=1RC = 10^4 \cdot 10^{-4} = 1 second and E/R=5×10−4E/R = 5 \times 10^{-4} amperes, so, with tt in seconds, q′+q=5×10−4,q' + q = 5 \times 10^{-4}\mathclose{\text{,}} and μ=et.\mu = e^t\mathclose{\text{.}} Then (etq)′=5×10−4et,(e^tq)' = 5 \times 10^{-4}e^t\mathclose{\text{,}} and etq=5×10−4et+A,e^tq = 5 \times 10^{-4}e^t + A\mathclose{\text{,}} where the constant is called AA because CC is taken. So q=5×10−4+Ae−t,q = 5 \times 10^{-4} + Ae^{-t}\mathclose{\text{,}} and q(0)=0q(0) = 0 gives A=−5×10−4:A = -5 \times 10^{-4}\mathclose{\text{:}}

q(t)=5×10−4(1−e−t) coulombs,qC=5(1−e−t) volts.\begin{aligned} q(t) &= 5 \times 10^{-4}\big(1 - e^{-t}\big) \text{ coulombs}, \\ \frac{q}{C} &= 5\big(1 - e^{-t}\big) \text{ volts}. \end{aligned}

After 1 second the capacitor is at 5(1−e−1)≈3.165(1 - e^{-1}) \approx 3.16 volts, 63% of the way to 5 volts; after 5 seconds, at about 4.97 volts.

In general the solution is q=CE(1−e−t/(RC)):q = CE\big(1 - e^{-t/(RC)}\big)\mathclose{\text{:}} the product τ=RC\tau = RC (read “tau”), measured in seconds, is the circuit’s time constant, as in the key idea of Section 13.5. Such a circuit is the simplest low-pass filter: it follows slow changes of its input voltage and smooths out fast ones (Exercise 13.12).

Watch out

Two slips with integrating factors. Compute μ\mu from the standard form: for 2y′+4y=6,2y' + 4y = 6\mathclose{\text{,}} divide by 2 first, so p=2p = 2 and μ=e2t,\mu = e^{2t}\mathclose{\text{,}} not e4t.e^{4t}\mathclose{\text{.}} And divide the constant by μ\mu too: from μy=R+C,\mu y = R + C\mathclose{\text{,}} y=Rμ+Cμ.y = \dfrac{R}{\mu} + \dfrac{C}{\mu}\mathclose{\text{.}} In Example 13.10, forgetting that gives t−1+Ct - 1 + C instead of t−1+Ce−t,t - 1 + Ce^{-t}\mathclose{\text{,}} and y=t−1+Cy = t - 1 + C is not a solution unless C=0.C = 0\mathclose{\text{.}}

8

Second-order linear equations

Pull a mass on a spring and let go: it moves back and forth, less and less, and comes to rest. Think of a mass of mm kilograms on a smooth horizontal table, attached to a spring, and let x(t)x(t) be its displacement in metres from the rest position after tt seconds, positive when the spring is stretched and negative when it is compressed. Two forces act on it. The spring pulls back with a force −kx-kx proportional to the displacement (Hooke’s law; the constant k>0,k > 0\mathclose{\text{,}} in newtons per metre, is the spring’s stiffness). A damper, such as a car’s shock absorber, resists the motion with a force −cx′-cx' proportional to the velocity, with a damping constant c≥0c \ge 0 in newton-seconds per metre. Mass times acceleration is the total force, so mx′′=−kx−cx′,mx'' = -kx - cx'\mathclose{\text{,}} that is,

mx′′+cx′+kx=0.mx'' + cx' + kx = 0.

The same equation, with charge in place of displacement, describes an electric circuit with an inductor, a resistor and a capacitor: Lq′′+Rq′+q/C=0.Lq'' + Rq' + q/C = 0\mathclose{\text{.}}

No damping. With c=0c = 0 the equation says x′′=−kmx:x'' = -\tfrac{k}{m}x\mathclose{\text{:}} the second derivative is a negative multiple of the function. Example 13.2 suggests what to try: with ω=k/m\omega = \sqrt{k/m} (read “omega”), (cos⁡ωt)′′=−ω2cos⁡ωt(\cos\omega t)'' = -\omega^2\cos\omega t and (sin⁡ωt)′′=−ω2sin⁡ωt,(\sin\omega t)'' = -\omega^2\sin\omega t\mathclose{\text{,}} so x=C1cos⁡ωt+C2sin⁡ωtx = C_1\cos\omega t + C_2\sin\omega t is a solution. The mass oscillates for ever with period 2π/ω=2πm/k:2\pi/\omega = 2\pi\sqrt{m/k}\mathclose{\text{:}} simple harmonic motion. A stiffer spring or a lighter mass oscillates faster.

A pendulum of length ℓ\ell obeys θ′′=−gℓsin⁡θ,\theta'' = -\tfrac{g}{\ell}\sin\theta\mathclose{\text{,}} where θ\theta is its angle from the vertical. For small swings, replacing sin⁡θ\sin\theta by θ\theta (Section 7.2) gives θ′′=−gℓθ,\theta'' = -\tfrac{g}{\ell}\theta\mathclose{\text{,}} the same equation with ω=g/ℓ:\omega = \sqrt{g/\ell}\mathclose{\text{:}} the pendulum swings with period 2πℓ/g,2\pi\sqrt{\ell/g}\mathclose{\text{,}} whatever the size of its swings, as long as they stay small.

The general equation. The spring equation is an instance of

ay′′+by′+cy=0,ay'' + by' + cy = 0,

with constants a≠0,a \ne 0\mathclose{\text{,}} bb and c:c\mathclose{\text{:}} a second-order linear homogeneous equation with constant coefficients (“homogeneous” because the right side is 0). Two facts make it manageable.

Theorem 13.6Superposition

If y1y_1 and y2y_2 are solutions of ay′′+by′+cy=0,ay'' + by' + cy = 0\mathclose{\text{,}} then so is C1y1+C2y2,C_1y_1 + C_2y_2\mathclose{\text{,}} for all constants C1C_1 and C2.C_2\mathclose{\text{.}}

Proof

Let Y=C1y1+C2y2.Y = C_1y_1 + C_2y_2\mathclose{\text{.}} Derivatives of sums and constant multiples are the sums and constant multiples of the derivatives (Module 4), so Y′=C1y1′+C2y2′Y' = C_1y_1' + C_2y_2' and Y′′=C1y1′′+C2y2′′.Y'' = C_1y_1'' + C_2y_2''\mathclose{\text{.}} Collect the terms with C1C_1 and those with C2:C_2\mathclose{\text{:}}

aY′′+bY′+cY=C1(ay1′′+by1′+cy1)+C2(ay2′′+by2′+cy2)=C1⋅0+C2⋅0=0.\begin{aligned} &aY'' + bY' + cY \\ &\quad= C_1\big(ay_1'' + by_1' + cy_1\big) \\ &\qquad + C_2\big(ay_2'' + by_2' + cy_2\big) \\ &\quad= C_1 \cdot 0 + C_2 \cdot 0 = 0. \end{aligned}
∎
Theorem 13.7Existence and uniqueness for ay′′+by′+cy=0ay'' + by' + cy = 0

Let a≠0,a \ne 0\mathclose{\text{,}} bb and cc be constants. For all numbers t0,t_0\mathclose{\text{,}} y0y_0 and v0,v_0\mathclose{\text{,}} the equation ay′′+by′+cy=0ay'' + by' + cy = 0 has a solution with y(t0)=y0y(t_0) = y_0 and y′(t0)=v0y'(t_0) = v_0 that is defined for every t,t\mathclose{\text{,}} and only one: any solution with these two values on an open interval containing t0t_0 agrees with it there.

As with Theorem 13.1, this series uses the theorem without proof, although the formulas of Theorem 13.8 below prove the existence half. It says that a solution is decided by two numbers, the starting position and the starting velocity, which is why two constants appear.

Trying exponentials. Exponentials keep their shape when differentiated, so try y=ert.y = e^{rt}\mathclose{\text{.}} Then y′=rerty' = re^{rt} and y′′=r2ert,y'' = r^2e^{rt}\mathclose{\text{,}} and

ay′′+by′+cy=(ar2+br+c)ert.ay'' + by' + cy = \big(ar^2 + br + c\big)e^{rt}.

Since erte^{rt} is never 0, y=erty = e^{rt} is a solution exactly when

ar2+br+c=0,ar^2 + br + c = 0,

the characteristic equation of the differential equation. Its roots are r=−b±b2−4ac2a,r = \dfrac{-b \pm \sqrt{b^2 - 4ac}}{2a}\mathclose{\text{,}} and the sign of the discriminant b2−4acb^2 - 4ac decides what the solutions look like.

Theorem 13.8Solutions of ay′′+by′+cy=0ay'' + by' + cy = 0

Let a≠0,a \ne 0\mathclose{\text{,}} bb and cc be constants. Every solution of ay′′+by′+cy=0ay'' + by' + cy = 0 has the following form, for some constants C1C_1 and C2,C_2\mathclose{\text{,}} and every function of this form is a solution.

  1. If b2−4ac>0,b^2 - 4ac > 0\mathclose{\text{,}} the characteristic equation has two real roots r1≠r2,r_1 \ne r_2\mathclose{\text{,}} and y=C1er1t+C2er2t.y = C_1e^{r_1t} + C_2e^{r_2t}\mathclose{\text{.}}
  2. If b2−4ac=0,b^2 - 4ac = 0\mathclose{\text{,}} it has one root r=−b2a,r = -\dfrac{b}{2a}\mathclose{\text{,}} and y=(C1+C2t) ert.y = (C_1 + C_2t)\,e^{rt}\mathclose{\text{.}}
  3. If b2−4ac<0,b^2 - 4ac < 0\mathclose{\text{,}} it has no real roots, and y=eαt(C1cos⁡βt+C2sin⁡βt),y = e^{\alpha t}\big(C_1\cos\beta t + C_2\sin\beta t\big)\mathclose{\text{,}} where α=−b2a\alpha = -\dfrac{b}{2a} and β=4ac−b22a\beta = \dfrac{\sqrt{4ac - b^2}}{2a} (read “alpha” and “beta”).
Proof

Each formula is a solution. By Theorem 13.6 it is enough to check the two functions that each formula combines. In case 1, er1te^{r_1t} and er2te^{r_2t} are solutions, as shown above. In case 2, so is ert;e^{rt}\mathclose{\text{;}} for y=tert,y = te^{rt}\mathclose{\text{,}} the product rule gives y′=(1+rt)erty' = (1 + rt)e^{rt} and y′′=(2r+r2t)ert,y'' = (2r + r^2t)e^{rt}\mathclose{\text{,}} so

ay′′+by′+cy=[(ar2+br+c)t+(2ar+b)]ert=0,\begin{aligned} &ay'' + by' + cy \\ &\quad= \Big[\big(ar^2 + br + c\big)t + (2ar + b)\Big]e^{rt} \\ &\quad= 0, \end{aligned}

because ar2+br+c=0ar^2 + br + c = 0 and 2ar+b=02ar + b = 0 when r=−b/(2a).r = -b/(2a)\mathclose{\text{.}} In case 3, for y=eαtcos⁡βt,y = e^{\alpha t}\cos\beta t\mathclose{\text{,}}

y′=eαt(αcos⁡βt−βsin⁡βt),y′′=eαt((α2−β2)cos⁡βt−2αβsin⁡βt),\begin{aligned} y' &= e^{\alpha t}\big(\alpha\cos\beta t - \beta\sin\beta t\big), \\ y'' &= e^{\alpha t}\big((\alpha^2 - \beta^2)\cos\beta t \\ &\qquad - 2\alpha\beta\sin\beta t\big), \end{aligned}

so ay′′+by′+cy=eαt(Pcos⁡βt−Qsin⁡βt),ay'' + by' + cy = e^{\alpha t}\big(P\cos\beta t - Q\sin\beta t\big)\mathclose{\text{,}} where

P=a(α2−β2)+bα+c,Q=(2aα+b)β.\begin{aligned} P &= a(\alpha^2 - \beta^2) + b\alpha + c, \\ Q &= (2a\alpha + b)\beta. \end{aligned}

Here 2aα+b=0,2a\alpha + b = 0\mathclose{\text{,}} so Q=0;Q = 0\mathclose{\text{;}} and since aα2=b24a,a\alpha^2 = \dfrac{b^2}{4a}\mathclose{\text{,}} aβ2=4ac−b24aa\beta^2 = \dfrac{4ac - b^2}{4a} and bα=−b22a,b\alpha = -\dfrac{b^2}{2a}\mathclose{\text{,}}

P=b24a−4ac−b24a−b22a+c=0.P = \frac{b^2}{4a} - \frac{4ac - b^2}{4a} - \frac{b^2}{2a} + c = 0.

The same calculation works for eαtsin⁡βt.e^{\alpha t}\sin\beta t\mathclose{\text{.}}

Every solution has this form. Let yy be any solution, say on an interval that contains 0 (on another interval, use one of its points in place of 0; the algebra is the same, with extra exponential factors). In each case, choose the constants so that the formula has the same value and the same derivative as yy at t=0.t = 0\mathclose{\text{.}} In case 1 that means C1+C2=y(0)C_1 + C_2 = y(0) and r1C1+r2C2=y′(0),r_1C_1 + r_2C_2 = y'(0)\mathclose{\text{,}} which can be solved because r1≠r2;r_1 \ne r_2\mathclose{\text{;}} in case 2, C1=y(0)C_1 = y(0) and rC1+C2=y′(0);rC_1 + C_2 = y'(0)\mathclose{\text{;}} in case 3, C1=y(0)C_1 = y(0) and αC1+βC2=y′(0),\alpha C_1 + \beta C_2 = y'(0)\mathclose{\text{,}} which can be solved because β≠0.\beta \ne 0\mathclose{\text{.}} Then yy and the formula solve the same initial value problem, so yy agrees with the formula on its interval, by Theorem 13.7.

∎

In case 3 the characteristic equation has no real roots. In the complex numbers, where i2=−1,i^2 = -1\mathclose{\text{,}} its roots are α±βi,\alpha \pm \beta i\mathclose{\text{,}} and Module 15 shows, with Euler’s formula eiθ=cos⁡θ+isin⁡θ,e^{i\theta} = \cos\theta + i\sin\theta\mathclose{\text{,}} how e(α+βi)te^{(\alpha + \beta i)t} produces eαtcos⁡βte^{\alpha t}\cos\beta t and eαtsin⁡βt.e^{\alpha t}\sin\beta t\mathclose{\text{.}} Here they were checked directly, which is all a proof needs.

Springs again. For mx′′+cx′+kx=0mx'' + cx' + kx = 0 with m>0,m > 0\mathclose{\text{,}} k>0k > 0 and c≥0,c \ge 0\mathclose{\text{,}} the discriminant is c2−4mk,c^2 - 4mk\mathclose{\text{,}} and the three cases have names:

  • Overdamped, c2>4mk:c^2 > 4mk\mathclose{\text{:}} two negative roots (their sum −c/m-c/m is negative and their product k/mk/m positive), so xx is a combination of two decaying exponentials and does not oscillate.
  • Critically damped, c2=4mk:c^2 = 4mk\mathclose{\text{:}} x=(C1+C2t)e−ct/(2m),x = (C_1 + C_2t)e^{-ct/(2m)}\mathclose{\text{,}} which does not oscillate either.
  • Underdamped, c2<4mk:c^2 < 4mk\mathclose{\text{:}} x=e−ct/(2m)(C1cos⁡βt+C2sin⁡βt)x = e^{-ct/(2m)}\big(C_1\cos\beta t + C_2\sin\beta t\big) with β=4mk−c2/(2m),\beta = \sqrt{4mk - c^2}/(2m)\mathclose{\text{,}} an oscillation whose size shrinks like e−ct/(2m).e^{-ct/(2m)}\mathclose{\text{.}} With c=0c = 0 it is simple harmonic motion.
Example 13.13An underdamped spring✓ Checked

A mass of 1 kg is attached to a spring with k=5k = 5 N/m and damping constant c=2c = 2 N·s/m. It is pulled 1 m from its rest position and released, so x(0)=1x(0) = 1 and x′(0)=0.x'(0) = 0\mathclose{\text{.}} Find x(t).x(t)\mathclose{\text{.}}

The equation is x′′+2x′+5x=0,x'' + 2x' + 5x = 0\mathclose{\text{,}} with characteristic equation r2+2r+5=0.r^2 + 2r + 5 = 0\mathclose{\text{.}} Its discriminant is 4−20=−16<0,4 - 20 = -16 < 0\mathclose{\text{,}} so the motion is underdamped, with α=−22=−1\alpha = -\tfrac22 = -1 and β=162=2:\beta = \tfrac{\sqrt{16}}{2} = 2\mathclose{\text{:}}

x=e−t(C1cos⁡2t+C2sin⁡2t).x = e^{-t}\big(C_1\cos 2t + C_2\sin 2t\big).

x(0)=C1=1.x(0) = C_1 = 1\mathclose{\text{.}} By the product rule, x′=e−t((2C2−C1)cos⁡2t−(C2+2C1)sin⁡2t),x' = e^{-t}\big((2C_2 - C_1)\cos 2t - (C_2 + 2C_1)\sin 2t\big)\mathclose{\text{,}} so x′(0)=2C2−C1=0,x'(0) = 2C_2 - C_1 = 0\mathclose{\text{,}} and C2=12:C_2 = \tfrac12\mathclose{\text{:}}

x=e−t(cos⁡2t+12sin⁡2t).x = e^{-t}\Big(\cos 2t + \tfrac12\sin 2t\Big).

The mass swings through its rest position every π/2\pi/2 seconds, a full oscillation every π\pi seconds, and the size of the swings shrinks like e−t.e^{-t}\mathclose{\text{.}}

Example 13.14Critical damping✓ Checked

A mass of 1 kg is attached to a spring with k=4k = 4 N/m. Which damping constant makes the motion critically damped? Find the motion from x(0)=1,x(0) = 1\mathclose{\text{,}} x′(0)=0x'(0) = 0 for that damping, and for c=10.c = 10\mathclose{\text{.}}

Critical damping needs c2=4mk=16,c^2 = 4mk = 16\mathclose{\text{,}} so c=4.c = 4\mathclose{\text{.}} Then r2+4r+4=(r+2)2=0,r^2 + 4r + 4 = (r + 2)^2 = 0\mathclose{\text{,}} with the single root r=−2,r = -2\mathclose{\text{,}} and x=(C1+C2t)e−2t.x = (C_1 + C_2t)e^{-2t}\mathclose{\text{.}} x(0)=C1=1,x(0) = C_1 = 1\mathclose{\text{,}} and x′(0)=−2C1+C2=0x'(0) = -2C_1 + C_2 = 0 gives C2=2:C_2 = 2\mathclose{\text{:}}

x=(1+2t) e−2t.x = (1 + 2t)\,e^{-2t}.

With c=10c = 10 the characteristic equation r2+10r+4=0r^2 + 10r + 4 = 0 has the roots r=−5±21,r = -5 \pm \sqrt{21}\mathclose{\text{,}} about −0.417-0.417 and −9.58:-9.58\mathclose{\text{:}} overdamped. The same initial conditions give C1+C2=1C_1 + C_2 = 1 and r1C1+r2C2=0,r_1C_1 + r_2C_2 = 0\mathclose{\text{,}} so C1≈1.046C_1 \approx 1.046 and C2≈−0.046.C_2 \approx -0.046\mathclose{\text{.}} The slowly decaying term 1.046e−0.417t1.046e^{-0.417t} dominates: at t=3t = 3 the overdamped mass is still at about 0.30 m, while the critically damped one is at 7e−6≈0.0177e^{-6} \approx 0.017 m. More damping does not mean a faster return. Critical damping is the least damping that prevents oscillation, and in the long run it brings the mass to rest at the fastest exponential rate: here e−2t,e^{-2t}\mathclose{\text{,}} against e−0.417te^{-0.417t} for c=10c = 10 and e−t/2e^{-t/2} for c=1c = 1 (Figure 13.5).

A mass of 1 kg on a spring with k = 4 N/m, released from x = 1 at rest. Left: with c = 1 the motion is underdamped; it oscillates inside the dashed envelope pm 1.03e^{-t/2}. Right: with c = 4 (critical damping) and c = 10 (overdamped) it does not oscillate, and the critically damped mass comes to rest much sooner.
Figure 13.5

A mass of 1 kg on a spring with k=4k = 4 N/m, released from x=1x = 1 at rest. Left: with c=1c = 1 the motion is underdamped; it oscillates inside the dashed envelope ±1.03e−t/2.\pm 1.03e^{-t/2}\mathclose{\text{.}} Right: with c=4c = 4 (critical damping) and c=10c = 10 (overdamped) it does not oscillate, and the critically damped mass comes to rest much sooner.

Watch out

With a repeated root r,r\mathclose{\text{,}} the formula C1ert+C2ertC_1e^{rt} + C_2e^{rt} is not the general solution: it is (C1+C2)ert,(C_1 + C_2)e^{rt}\mathclose{\text{,}} a single constant times ert,e^{rt}\mathclose{\text{,}} and it cannot meet two initial conditions. For x′′+4x′+4x=0x'' + 4x' + 4x = 0 with x(0)=1x(0) = 1 and x′(0)=0,x'(0) = 0\mathclose{\text{,}} it would need C1+C2=1C_1 + C_2 = 1 and −2(C1+C2)=0-2(C_1 + C_2) = 0 at once. The second solution is tert.te^{rt}\mathclose{\text{.}} And in case 3, β\beta is 4ac−b2/(2a),\sqrt{4ac - b^2}/(2a)\mathclose{\text{,}} the square root of the positive number 4ac−b2.4ac - b^2\mathclose{\text{.}}

9

Solving with a computer

SymPy solves many differential equations exactly with dsolve, and checkodesol checks a proposed solution by substituting it, as you did by hand in Example 13.1. The unknown must be a SymPy function, made with sp.Function, not a symbol; derivatives are written with .diff, and the equation with sp.Eq.

Compute itExact solutions with dsolve

The equation of Examples 13.1 and 13.10, without and with an initial condition:

Python
import sympy as sp
t = sp.symbols('t')
y = sp.Function('y')                   # an unknown function of t
ode = sp.Eq(y(t).diff(t), t - y(t))    # y' = t - y
print(sp.dsolve(ode))
sol = sp.dsolve(ode, ics={y(0): 1})    # with the initial condition y(0) = 1
print(sol)
print(sp.checkodesol(ode, sol))
Output
Eq(y(t), C1*exp(-t) + t - 1)
Eq(y(t), t - 1 + 2*exp(-t))
(True, 0)

The first line is the general solution, with SymPy’s name C1 for the constant; the second is the solution of Example 13.1. checkodesol substitutes the solution into the equation: (True, 0) means that the two sides differ by 0. Next, a logistic equation and the spring of Example 13.13; a condition on a derivative is written with .diff(t).subs(t, 0):

Python
logistic = sp.Eq(y(t).diff(t), y(t)*(1 - y(t)))
print(sp.dsolve(logistic, ics={y(0): sp.Rational(1, 10)}))
x = sp.Function('x')
spring = sp.Eq(x(t).diff(t, 2) + 2*x(t).diff(t) + 5*x(t), 0)
print(sp.dsolve(spring))
print(sp.dsolve(spring, ics={x(0): 1, x(t).diff(t).subs(t, 0): 0}))
Output
Eq(y(t), 1/(1 + 9*exp(-t)))
Eq(x(t), (C1*sin(2*t) + C2*cos(2*t))*exp(-t))
Eq(x(t), (sin(2*t)/2 + cos(2*t))*exp(-t))

The logistic solution is the formula of Section 13.6 with K=1,K = 1\mathclose{\text{,}} r=1r = 1 and y0=110,y_0 = \tfrac{1}{10}\mathclose{\text{,}} so that (K−y0)/y0=9.(K - y_0)/y_0 = 9\mathclose{\text{.}} In the general solution of the spring equation SymPy attaches C1 to the sine and C2 to the cosine, the other way round from Theorem 13.8; that changes nothing, since both constants are arbitrary. The last line is the answer of Example 13.13. The most common mistake is to make the unknown a symbol:

Pythonraises an error on purpose
z = sp.symbols('z')                    # a symbol, not a function
print(sp.dsolve(sp.Eq(z(t).diff(t), z(t))))
Error
TypeError: 'Symbol' object is not callable

A symbol stands for a number, and z(t) asks for “z at t”, which makes sense only for a function.

Not every equation has a formula. For y′=t−y2,y' = t - y^2\mathclose{\text{,}} one of the equations in the widget, no formula built from the functions of this course solves it (its solutions need special functions, the Airy functions), and dsolve does not produce one: SymPy 1.14 stops with an error message. Numerical methods do not care. Run RK4 with a step hh and again with h/2:h/2\mathclose{\text{:}} the digits that do not change are usually the ones you can trust.

Compute itNumerical solutions

The solution of y′=t−y2,y' = t - y^2\mathclose{\text{,}} y(0)=0,y(0) = 0\mathclose{\text{,}} at t=2,t = 2\mathclose{\text{,}} with the rk4 function of Section 13.4 and three step sizes:

Python
def rk4(F, t, y, h, n):
    """n steps of the classical Runge-Kutta method; returns the last y."""
    for _ in range(n):
        k1 = F(t, y)
        k2 = F(t + h/2, y + h/2*k1)
        k3 = F(t + h/2, y + h/2*k2)
        k4 = F(t + h, y + h*k3)
        y, t = y + h/6*(k1 + 2*k2 + 2*k3 + k4), t + h
    return y

F = lambda t, y: t - y**2
for n in [20, 40, 80]:
    print(f"h = {2/n:<6} y(2) = {rk4(F, 0.0, 0.0, 2/n, n):.10f}")
Output
h = 0.1    y(2) = 1.1935739964
h = 0.05   y(2) = 1.1935758583
h = 0.025  y(2) = 1.1935759682

From h=0.05h = 0.05 on, the values agree to six decimal places: y(2)≈1.193576.y(2) \approx 1.193576\mathclose{\text{.}} A second-order equation becomes a pair of first-order ones. For the spring of Example 13.13, x′′=−2x′−5x,x'' = -2x' - 5x\mathclose{\text{,}} call the velocity v=x′;v = x'\mathclose{\text{;}} then x′=vx' = v and v′=−2v−5x.v' = -2v - 5x\mathclose{\text{.}} The same rk4 works with a NumPy array u=(x,v)u = (x, v) in place of a number, because it only adds and multiplies:

Python
import numpy as np
G = lambda t, u: np.array([u[1], -2*u[1] - 5*u[0]])   # (x, v) -> (x', v')
u = rk4(G, 0.0, np.array([1.0, 0.0]), 0.01, 300)     # 300 steps, to t = 3
exact = np.exp(-3)*(np.cos(6) + np.sin(6)/2)          # Example 13.13, t = 3
print(f"RK4: x(3) = {u[0]:.10f}   exact: {exact:.10f}")
Output
RK4: x(3) = 0.0408484252   exact: 0.0408484245

The two differ by less than 10−9.10^{-9}\mathclose{\text{.}} Libraries such as SciPy do the same with more care: their solvers choose and adjust the step automatically to meet an error tolerance that you set.

10

What you learned

  • A differential equation relates an unknown function to its derivatives; its order is that of the highest derivative. A solution makes the equation true on an interval, and you check one by substituting it. An initial value problem adds y(t0)=y0,y(t_0) = y_0\mathclose{\text{,}} and y′(t0)=v0y'(t_0) = v_0 for a second-order equation.
  • If FF and FyF_y are continuous, y′=F(t,y),y' = F(t, y)\mathclose{\text{,}} y(t0)=y0y(t_0) = y_0 has exactly one solution near t0t_0 (Theorem 13.1), although it may blow up after a finite time; without the condition on Fy,F_y\mathclose{\text{,}} uniqueness can fail.
  • Models come from “rate of change = rate in − rate out”: growth and decay y′=ky,y' = ky\mathclose{\text{,}} cooling T′=−k(T−Ts),T' = -k(T - T_s)\mathclose{\text{,}} a falling body mv′=mg−cv,mv' = mg - cv\mathclose{\text{,}} and mixing tanks.
  • A direction field shows the solutions before you solve anything. For y′=f(y),y' = f(y)\mathclose{\text{,}} the equilibria are the zeros of f;f\mathclose{\text{;}} an equilibrium is stable if f′(y∗)<0f'(y^*) < 0 and unstable if f′(y∗)>0,f'(y^*) > 0\mathclose{\text{,}} and the signs of ff on the phase line tell where every solution goes.
  • Euler’s method, yn+1=yn+h F(tn,yn),y_{n+1} = y_n + h\,F(t_n, y_n)\mathclose{\text{,}} follows tangent lines. Its error at a fixed time is O(h),O(h)\mathclose{\text{,}} so halving hh roughly halves it; for a smooth F,F\mathclose{\text{,}} RK4’s is O(h4).O(h^4)\mathclose{\text{.}} Too large a step can make Euler’s method swing out of control.
  • Separable equations y′=g(t)h(y):y' = g(t)h(y)\mathclose{\text{:}} ∫dyh(y)=∫g(t) dt,\int\frac{dy}{h(y)} = \int g(t)\,dt\mathclose{\text{,}} justified by the chain rule; constant solutions with h(y∗)=0h(y^*) = 0 get lost and must be added back. The solutions of y′=kyy' = ky are exactly y(t0)ek(t−t0),y(t_0)e^{k(t - t_0)}\mathclose{\text{,}} and those of y′=−k(y−A)y' = -k(y - A) are A+(y(0)−A)e−kt:A + \big(y(0) - A\big)e^{-kt}\mathclose{\text{:}} cooling, falling bodies, tanks and RC circuits.
  • The logistic equation y′=ry(1−y/K)y' = ry(1 - y/K) has the S-shaped solution y=K/(1+K−y0y0e−rt),y = K\big/\big(1 + \frac{K - y_0}{y_0}e^{-rt}\big)\mathclose{\text{,}} with carrying capacity KK and the fastest growth at y=K/2.y = K/2\mathclose{\text{.}}
  • Linear equations y′+p(t)y=q(t):y' + p(t)y = q(t)\mathclose{\text{:}} multiply by μ=e∫p dt,\mu = e^{\int p\,dt}\mathclose{\text{,}} so that the left side is (μy)′,(\mu y)'\mathclose{\text{,}} and integrate; the solution exists wherever pp and qq are continuous.
  • ay′′+by′+cy=0:ay'' + by' + cy = 0\mathclose{\text{:}} the roots of ar2+br+c=0ar^2 + br + c = 0 give C1er1t+C2er2t,C_1e^{r_1t} + C_2e^{r_2t}\mathclose{\text{,}} (C1+C2t)ert(C_1 + C_2t)e^{rt} or eαt(C1cos⁡βt+C2sin⁡βt);e^{\alpha t}(C_1\cos\beta t + C_2\sin\beta t)\mathclose{\text{;}} for springs these are overdamped, critically damped and underdamped motion.
  • SymPy: sp.Function, sp.dsolve(ode, ics=...) and sp.checkodesol; numerically, RK4, with a second-order equation turned into a first-order system.
11

Exercises

Exercise 13.1★Orders and solutions
  • (a) State the order of each equation: (i) y′+ty=et;y' + ty = e^t\mathclose{\text{;}} (ii) y′′=6y−y′;y'' = 6y - y'\mathclose{\text{;}} (iii) (y′)2+y=t.(y')^2 + y = t\mathclose{\text{.}}
  • (b) Show that y=3+Ce−2ty = 3 + Ce^{-2t} is a solution of y′=6−2yy' = 6 - 2y for every constant C,C\mathclose{\text{,}} and find the solution with y(0)=1.y(0) = 1\mathclose{\text{.}}
  • (c) Which solution is constant, and what do the other solutions do as t→∞?t \to \infty\mathclose{\text{?}}
Show solution✓ Checked

(a) (i) Order 1. (ii) Order 2: the highest derivative is y′′.y''\mathclose{\text{.}} (iii) Order 1: the highest derivative is y′,y'\mathclose{\text{,}} and squaring it does not change the order.

(b) Differentiate: y′=−2Ce−2t.y' = -2Ce^{-2t}\mathclose{\text{.}} The right side is 6−2y=6−2(3+Ce−2t)=−2Ce−2t.6 - 2y = 6 - 2\big(3 + Ce^{-2t}\big) = -2Ce^{-2t}\mathclose{\text{.}} The two sides agree for every t,t\mathclose{\text{,}} so every function of the family is a solution. Then y(0)=3+C=1y(0) = 3 + C = 1 gives C=−2:C = -2\mathclose{\text{:}}

y=3−2e−2t.y = 3 - 2e^{-2t}.

(c) C=0C = 0 gives the constant solution y=3,y = 3\mathclose{\text{,}} the equilibrium: 6−2⋅3=0.6 - 2 \cdot 3 = 0\mathclose{\text{.}} For every other C,C\mathclose{\text{,}} Ce−2t→0,Ce^{-2t} \to 0\mathclose{\text{,}} so every solution approaches 3: the equilibrium is stable, as Theorem 13.2 confirms, since f(y)=6−2yf(y) = 6 - 2y has f′(3)=−2<0.f'(3) = -2 < 0\mathclose{\text{.}}

Exercise 13.2★Equilibria and stability

For y′=y2−y−2:y' = y^2 - y - 2\mathclose{\text{:}}

  • (a) Find the equilibria, and decide whether each is stable or unstable.
  • (b) Describe what the solutions with y(0)=0,y(0) = 0\mathclose{\text{,}} y(0)=3y(0) = 3 and y(0)=−2y(0) = -2 do as tt increases.
Show solution✓ Checked

(a) f(y)=y2−y−2=(y−2)(y+1),f(y) = y^2 - y - 2 = (y - 2)(y + 1)\mathclose{\text{,}} which is 0 at y=2y = 2 and y=−1.y = -1\mathclose{\text{.}} Since f′(y)=2y−1,f'(y) = 2y - 1\mathclose{\text{,}} f′(−1)=−3<0f'(-1) = -3 < 0 and f′(2)=3>0:f'(2) = 3 > 0\mathclose{\text{:}} −1-1 is stable and 2 is unstable.

(b) The signs of f:f\mathclose{\text{:}} for y<−1y < -1 both factors are negative, so f>0;f > 0\mathclose{\text{;}} for −1<y<2,-1 < y < 2\mathclose{\text{,}} f<0;f < 0\mathclose{\text{;}} for y>2,y > 2\mathclose{\text{,}} f>0.f > 0\mathclose{\text{.}}

  • y(0)=0y(0) = 0 lies between the equilibria, where f<0:f < 0\mathclose{\text{:}} the solution decreases and approaches −1,-1\mathclose{\text{,}} without ever reaching it.
  • y(0)=3y(0) = 3 lies above 2, where f>0:f > 0\mathclose{\text{:}} the solution increases, away from 2, without bound.
  • y(0)=−2y(0) = -2 lies below −1,-1\mathclose{\text{,}} where f>0:f > 0\mathclose{\text{:}} the solution increases and approaches −1-1 from below.
Exercise 13.3★Euler’s method by hand

For y′=y+t,y' = y + t\mathclose{\text{,}} y(0)=1:y(0) = 1\mathclose{\text{:}}

  • (a) Use Euler’s method with h=0.25h = 0.25 to approximate y(1).y(1)\mathclose{\text{.}}
  • (b) Check that y=2et−t−1y = 2e^t - t - 1 is the exact solution, and find the error of your approximation.
  • (c) Without computing, about what error would h=0.125h = 0.125 give?
Show solution✓ Checked

(a) Here F(t,y)=y+t,F(t, y) = y + t\mathclose{\text{,}} and four steps of 0.25 reach t=1.t = 1\mathclose{\text{.}} Each step adds 0.25 times the slope: yn+1=yn+0.25 (yn+tn).y_{n+1} = y_n + 0.25\,(y_n + t_n)\mathclose{\text{.}}

nn tnt_n yny_n slope yn+tny_n + t_n
0 0 1 1
1 0.25 1.25 1.5
2 0.5 1.625 2.125
3 0.75 2.15625 2.90625
4 1 2.8828125

So y(1)≈2.8828.y(1) \approx 2.8828\mathclose{\text{.}}

(b) For y=2et−t−1:y = 2e^t - t - 1\mathclose{\text{:}} y′=2et−1,y' = 2e^t - 1\mathclose{\text{,}} and y+t=2et−t−1+t=2et−1,y + t = 2e^t - t - 1 + t = 2e^t - 1\mathclose{\text{,}} the same; and y(0)=2−0−1=1.y(0) = 2 - 0 - 1 = 1\mathclose{\text{.}} So it is the solution, and y(1)=2e−2≈3.4366.y(1) = 2e - 2 \approx 3.4366\mathclose{\text{.}} The error is about 3.4366−2.8828=0.554.3.4366 - 2.8828 = 0.554\mathclose{\text{.}}

(c) Euler’s method has order 1, so halving hh should roughly halve the error, to about 0.28. (Eight steps of 0.125 give 3.1316, an error of 0.305: a little more than half, because hh is not yet small. Halving hh again and again, the ratio of successive errors is 1.82, 1.90, 1.95, 1.97: it approaches 2.)

Exercise 13.4★Two separable equations

Solve:

  • (a) y′=3t2y,y' = 3t^2y\mathclose{\text{,}} y(0)=5;y(0) = 5\mathclose{\text{;}}
  • (b) y′=ty,y' = \dfrac{t}{y}\mathclose{\text{,}} y(0)=−2.y(0) = -2\mathclose{\text{.}}
Show solution✓ Checked

(a) The solution cannot touch the equilibrium y=0y = 0 (by Theorem 13.1, since F=3t2yF = 3t^2y and Fy=3t2F_y = 3t^2 are continuous), so it stays positive and you may divide by y.y\mathclose{\text{.}} Separate and integrate:

∫dyy=∫3t2 dt,ln⁡y=t3+C,y=eCet3.\begin{aligned} \int\frac{dy}{y} &= \int 3t^2\,dt, \\ \ln y &= t^3 + C, \\ y &= e^{C}e^{t^3}. \end{aligned}

y(0)=eC=5,y(0) = e^C = 5\mathclose{\text{,}} so y=5et3.y = 5e^{t^3}\mathclose{\text{.}} Check: y′=5et3⋅3t2=3t2y.y' = 5e^{t^3} \cdot 3t^2 = 3t^2y\mathclose{\text{.}}

(b) Multiply by yy and integrate: ∫y dy=∫t dt,\displaystyle\int y\,dy = \int t\,dt\mathclose{\text{,}} so 12y2=12t2+C,\tfrac12y^2 = \tfrac12t^2 + C\mathclose{\text{,}} that is, y2=t2+2C.y^2 = t^2 + 2C\mathclose{\text{.}} At t=0:t = 0\mathclose{\text{:}} 4=2C,4 = 2C\mathclose{\text{,}} so

y2=t2+4.y^2 = t^2 + 4.

So y=t2+4y = \sqrt{t^2 + 4} or y=−t2+4.y = -\sqrt{t^2 + 4}\mathclose{\text{.}} Only the second has y(0)=−2,y(0) = -2\mathclose{\text{,}} and since t2+4t^2 + 4 is never 0, the solution cannot switch from one branch to the other: y=−t2+4y = -\sqrt{t^2 + 4} for every t.t\mathclose{\text{.}} The common wrong answer, t2+4,\sqrt{t^2 + 4}\mathclose{\text{,}} has y(0)=2.y(0) = 2\mathclose{\text{.}} Check: y′=−tt2+4=ty.y' = -\dfrac{t}{\sqrt{t^2 + 4}} = \dfrac{t}{y}\mathclose{\text{.}}

Exercise 13.5★★A thermometer

A thermometer reading 5 °C is brought into a room at 22 °C. After 1 minute it reads 12 °C. Assuming Newton’s law of cooling, when will it read 21 °C?

Show solution✓ Checked

Newton’s law covers warming too: when T<Ts,T < T_s\mathclose{\text{,}} T′=−k(T−Ts)>0.T' = -k(T - T_s) > 0\mathclose{\text{.}} By Section 13.5, T(t)=22+(5−22)e−kt=22−17e−kt,T(t) = 22 + (5 - 22)e^{-kt} = 22 - 17e^{-kt}\mathclose{\text{,}} with tt in minutes and kk per minute. At t=1:t = 1\mathclose{\text{:}}

12=22−17e−k,e−k=1017,k=ln⁡1.7≈0.531.\begin{aligned} 12 &= 22 - 17e^{-k}, \\ e^{-k} &= \frac{10}{17}, \\ k &= \ln 1.7 \approx 0.531. \end{aligned}

For 21 °C: 22−17e−kt=2122 - 17e^{-kt} = 21 gives e−kt=117,e^{-kt} = \tfrac{1}{17}\mathclose{\text{,}} so t=ln⁡17k,t = \dfrac{\ln 17}{k}\mathclose{\text{,}} that is,

t=ln⁡17ln⁡1.7≈5.34 minutes.t = \frac{\ln 17}{\ln 1.7} \approx 5.34 \text{ minutes}.
Exercise 13.6★★The tank and the falling body
  • (a) Solve the initial value problem of the mixing tank, Example 13.3: y′=0.6−0.03y,y' = 0.6 - 0.03y\mathclose{\text{,}} y(0)=5.y(0) = 5\mathclose{\text{.}} When does the tank hold 15 kg of salt?
  • (b) Solve v′=9.8−0.2v,v' = 9.8 - 0.2v\mathclose{\text{,}} v(0)=0,v(0) = 0\mathclose{\text{,}} the falling body of Section 13.2. How long does the body take to reach 95% of its terminal velocity?
Show solution✓ Checked

Both equations have the form y′=−k(y−A)y' = -k(y - A) of the key idea in Section 13.5, with solution A+(y(0)−A)e−kt.A + \big(y(0) - A\big)e^{-kt}\mathclose{\text{.}}

(a) y′=−0.03(y−20),y' = -0.03(y - 20)\mathclose{\text{,}} so

y=20+(5−20)e−0.03t=20−15e−0.03t.\begin{aligned} y &= 20 + (5 - 20)e^{-0.03t} \\ &= 20 - 15e^{-0.03t}. \end{aligned}

The tank holds 15 kg when 15e−0.03t=5,15e^{-0.03t} = 5\mathclose{\text{,}} that is, e−0.03t=13,e^{-0.03t} = \tfrac13\mathclose{\text{,}} at t=ln⁡30.03≈36.6t = \dfrac{\ln 3}{0.03} \approx 36.6 minutes.

(b) v′=−0.2(v−49),v' = -0.2(v - 49)\mathclose{\text{,}} so v=49+(0−49)e−0.2t=49(1−e−0.2t).v = 49 + (0 - 49)e^{-0.2t} = 49\big(1 - e^{-0.2t}\big)\mathclose{\text{.}} It reaches 95% of 49 m/s when 1−e−0.2t=0.95,1 - e^{-0.2t} = 0.95\mathclose{\text{,}} that is, e−0.2t=0.05,e^{-0.2t} = 0.05\mathclose{\text{,}} at t=ln⁡200.2:t = \dfrac{\ln 20}{0.2}\mathclose{\text{:}}

t=5ln⁡20≈15.0 seconds.t = 5\ln 20 \approx 15.0 \text{ seconds}.
Exercise 13.7★★An integrating factor

Solve ty′+2y=4t2ty' + 2y = 4t^2 for t>0,t > 0\mathclose{\text{,}} with y(1)=2.y(1) = 2\mathclose{\text{.}} Which solution of the equation stays finite as t→0+?t \to 0^+\mathclose{\text{?}}

Show solution✓ Checked

For t>0t > 0 you may divide by t,t\mathclose{\text{,}} which gives the standard form

y′+2t y=4t.y' + \frac{2}{t}\,y = 4t.

Here p(t)=2/tp(t) = 2/t is continuous on (0,∞),(0, \infty)\mathclose{\text{,}} with antiderivative 2ln⁡t,2\ln t\mathclose{\text{,}} so μ=e2ln⁡t=t2.\mu = e^{2\ln t} = t^2\mathclose{\text{.}} Multiply: t2y′+2ty=4t3,t^2y' + 2ty = 4t^3\mathclose{\text{,}} that is, (t2y)′=4t3.(t^2y)' = 4t^3\mathclose{\text{.}} Integrate: t2y=t4+C,t^2y = t^4 + C\mathclose{\text{,}} so

y=t2+Ct2.y = t^2 + \frac{C}{t^2}.

y(1)=1+C=2y(1) = 1 + C = 2 gives C=1:C = 1\mathclose{\text{:}} y=t2+1t2y = t^2 + \dfrac{1}{t^2} for t>0.t > 0\mathclose{\text{.}} By Theorem 13.5 it is the only solution with y(1)=2y(1) = 2 on (0,∞).(0, \infty)\mathclose{\text{.}} As t→0+t \to 0^+ (a one-sided limit), C/t2C/t^2 is unbounded unless C=0C = 0 (it tends to ∞\infty if C>0C > 0 and to −∞-\infty if C<0),C < 0\mathclose{\text{),}} so the only solution that stays finite is y=t2;y = t^2\mathclose{\text{;}} indeed it solves the original equation for every t,t\mathclose{\text{,}} since t⋅2t+2t2=4t2.t \cdot 2t + 2t^2 = 4t^2\mathclose{\text{.}}

Exercise 13.8★★A rumour

A rumour spreads through a school of 1000 students. Suppose it spreads at a rate proportional both to the number yy of students who have heard it and to the number 1000−y1000 - y who have not.

  • (a) Show that yy satisfies a logistic equation.
  • (b) At the start 100 students have heard it, and a day later 200. Find r.r\mathclose{\text{.}}
  • (c) When have 900 heard it?
Show solution✓ Checked

(a) y′=a y(1000−y)y' = a\,y(1000 - y) for a constant a>0.a > 0\mathclose{\text{.}} Taking 1000 out of the bracket, y′=1000a y(1−y1000):y' = 1000a\,y\big(1 - \tfrac{y}{1000}\big)\mathclose{\text{:}} the logistic equation with K=1000K = 1000 and r=1000a.r = 1000a\mathclose{\text{.}}

(b) With y0=100,y_0 = 100\mathclose{\text{,}} K−y0y0=9,\dfrac{K - y_0}{y_0} = 9\mathclose{\text{,}} so y=10001+9e−rt.y = \dfrac{1000}{1 + 9e^{-rt}}\mathclose{\text{.}} Then y(1)=200y(1) = 200 means 1+9e−r=5,1 + 9e^{-r} = 5\mathclose{\text{,}} so e−r=49e^{-r} = \tfrac49 and

r=ln⁡94≈0.811 per day.r = \ln\frac94 \approx 0.811 \text{ per day}.

(c) y=900y = 900 means 1+9e−rt=109,1 + 9e^{-rt} = \tfrac{10}{9}\mathclose{\text{,}} so e−rt=181e^{-rt} = \tfrac{1}{81} and

t=ln⁡81r=ln⁡81ln⁡(9/4)=2ln⁡3ln⁡1.5≈5.42 days.\begin{aligned} t &= \frac{\ln 81}{r} = \frac{\ln 81}{\ln(9/4)} \\ &= \frac{2\ln 3}{\ln 1.5} \approx 5.42 \text{ days}. \end{aligned}

This is exactly twice the time ln⁡9r≈2.71\dfrac{\ln 9}{r} \approx 2.71 days at which half the students have heard it: the logistic curve climbs from 100 to 500 as fast as from 500 to 900.

Exercise 13.9★★Three second-order equations

Solve:

  • (a) y′′−y′−6y=0,y'' - y' - 6y = 0\mathclose{\text{,}} y(0)=1,y(0) = 1\mathclose{\text{,}} y′(0)=8;y'(0) = 8\mathclose{\text{;}}
  • (b) y′′+6y′+9y=0,y'' + 6y' + 9y = 0\mathclose{\text{,}} y(0)=2,y(0) = 2\mathclose{\text{,}} y′(0)=−1;y'(0) = -1\mathclose{\text{;}}
  • (c) y′′+4y′+13y=0,y'' + 4y' + 13y = 0\mathclose{\text{,}} y(0)=0,y(0) = 0\mathclose{\text{,}} y′(0)=6.y'(0) = 6\mathclose{\text{.}}
Show solution✓ Checked

(a) r2−r−6=(r−3)(r+2)=0r^2 - r - 6 = (r - 3)(r + 2) = 0 gives r=3r = 3 and r=−2,r = -2\mathclose{\text{,}} so y=C1e3t+C2e−2t.y = C_1e^{3t} + C_2e^{-2t}\mathclose{\text{.}} The conditions: C1+C2=1C_1 + C_2 = 1 and 3C1−2C2=8.3C_1 - 2C_2 = 8\mathclose{\text{.}} Adding twice the first to the second gives 5C1=10,5C_1 = 10\mathclose{\text{,}} so C1=2C_1 = 2 and C2=−1:C_2 = -1\mathclose{\text{:}}

y=2e3t−e−2t.y = 2e^{3t} - e^{-2t}.

(b) r2+6r+9=(r+3)2=0r^2 + 6r + 9 = (r + 3)^2 = 0 has the single root r=−3,r = -3\mathclose{\text{,}} so y=(C1+C2t)e−3t.y = (C_1 + C_2t)e^{-3t}\mathclose{\text{.}} y(0)=C1=2;y(0) = C_1 = 2\mathclose{\text{;}} y′=(C2−3C1−3C2t)e−3t,y' = \big(C_2 - 3C_1 - 3C_2t\big)e^{-3t}\mathclose{\text{,}} so y′(0)=C2−3C1=−1y'(0) = C_2 - 3C_1 = -1 and C2=5:C_2 = 5\mathclose{\text{:}}

y=(2+5t) e−3t.y = (2 + 5t)\,e^{-3t}.

(c) r2+4r+13=0r^2 + 4r + 13 = 0 has discriminant 16−52=−36<0,16 - 52 = -36 < 0\mathclose{\text{,}} so α=−42=−2\alpha = -\tfrac42 = -2 and β=362=3:\beta = \tfrac{\sqrt{36}}{2} = 3\mathclose{\text{:}} y=e−2t(C1cos⁡3t+C2sin⁡3t).y = e^{-2t}\big(C_1\cos 3t + C_2\sin 3t\big)\mathclose{\text{.}} y(0)=C1=0,y(0) = C_1 = 0\mathclose{\text{,}} so y=C2e−2tsin⁡3t,y = C_2e^{-2t}\sin 3t\mathclose{\text{,}} with y′=C2e−2t(3cos⁡3t−2sin⁡3t);y' = C_2e^{-2t}\big(3\cos 3t - 2\sin 3t\big)\mathclose{\text{;}} y′(0)=3C2=6y'(0) = 3C_2 = 6 gives C2=2:C_2 = 2\mathclose{\text{:}}

y=2e−2tsin⁡3t.y = 2e^{-2t}\sin 3t.
Exercise 13.10★★★Euler’s method, exactly

Run Euler’s method with step h,h\mathclose{\text{,}} where 0<h<1,0 < h < 1\mathclose{\text{,}} on y′=t−y,y' = t - y\mathclose{\text{,}} y(0)=1,y(0) = 1\mathclose{\text{,}} so that tn=nh.t_n = nh\mathclose{\text{.}}

  • (a) Prove by induction that yn=tn−1+2(1−h)ny_n = t_n - 1 + 2(1 - h)^n for n=0,1,2,…n = 0, 1, 2, \dots
  • (b) Deduce that with nn steps to t=2t = 2 (so h=2/n),h = 2/n\mathclose{\text{),}} Euler’s approximation to y(2)y(2) is 1+2(1−2n)n,1 + 2\big(1 - \tfrac2n\big)^n\mathclose{\text{,}} and prove that it tends to the exact value 1+2e−21 + 2e^{-2} as n→∞.n \to \infty\mathclose{\text{.}}
  • (c) Check the formula against Example 13.6 and Figure 13.2, and show that every approximation yny_n with n≥1n \ge 1 lies below the exact value y(tn).y(t_n)\mathclose{\text{.}}
Show solution✓ Checked

(a) For n=0:n = 0\mathclose{\text{:}} t0−1+2(1−h)0=0−1+2=1=y0.t_0 - 1 + 2(1 - h)^0 = 0 - 1 + 2 = 1 = y_0\mathclose{\text{.}} Now suppose that yn=tn−1+2(1−h)ny_n = t_n - 1 + 2(1 - h)^n for some n.n\mathclose{\text{.}} Then

yn+1=yn+h(tn−yn)=(1−h)yn+htn=(1−h)(tn−1)+htn+2(1−h)n+1=tn−1+h+2(1−h)n+1=tn+1−1+2(1−h)n+1,\begin{aligned} y_{n+1} &= y_n + h(t_n - y_n) \\ &= (1 - h)y_n + ht_n \\ &= (1 - h)(t_n - 1) + ht_n \\ &\qquad + 2(1 - h)^{n+1} \\ &= t_n - 1 + h + 2(1 - h)^{n+1} \\ &= t_{n+1} - 1 + 2(1 - h)^{n+1}, \end{aligned}

where the third step substitutes the formula for yny_n and multiplies out, the fourth expands (1−h)(tn−1)+htn=tn−1−htn+h+htn=tn−1+h,(1 - h)(t_n - 1) + ht_n = t_n - 1 - ht_n + h + ht_n = t_n - 1 + h\mathclose{\text{,}} and the last uses tn+1=tn+h.t_{n+1} = t_n + h\mathclose{\text{.}} So the formula holds for n+1,n + 1\mathclose{\text{,}} and by induction for every n.n\mathclose{\text{.}}

(b) With h=2/n,h = 2/n\mathclose{\text{,}} tn=2,t_n = 2\mathclose{\text{,}} so yn=2−1+2(1−2n)n=1+2(1−2n)n.y_n = 2 - 1 + 2\big(1 - \tfrac2n\big)^n = 1 + 2\big(1 - \tfrac2n\big)^n\mathclose{\text{.}} Module 6 proved that (1+xn)n→ex\big(1 + \tfrac{x}{n}\big)^n \to e^x for every x;x\mathclose{\text{;}} with x=−2,x = -2\mathclose{\text{,}} (1−2n)n→e−2,\big(1 - \tfrac2n\big)^n \to e^{-2}\mathclose{\text{,}} so yn→1+2e−2=y(2).y_n \to 1 + 2e^{-2} = y(2)\mathclose{\text{.}} (Or directly: ln⁡(1−2n)n=nln⁡(1−2n)→−2,\ln\big(1 - \tfrac2n\big)^n = n\ln\big(1 - \tfrac2n\big) \to -2\mathclose{\text{,}} a limit of the form ∞⋅0\infty \cdot 0 that L’Hôpital’s rule settles.) Euler’s method converges to the solution as the step shrinks.

(c) n=4n = 4 (h=0.5):h = 0.5\mathclose{\text{):}} 1+2(12)4=1.125,1 + 2\big(\tfrac12\big)^4 = 1.125\mathclose{\text{,}} as in Example 13.6. n=8n = 8 (h=0.25):h = 0.25\mathclose{\text{):}} 1+2(34)8=1+656132768≈1.2002,1 + 2\big(\tfrac34\big)^8 = 1 + \tfrac{6561}{32768} \approx 1.2002\mathclose{\text{,}} as in Figure 13.2.

For the comparison, the exact solution of Example 13.1 gives y(tn)=tn−1+2e−nh=tn−1+2(e−h)n.y(t_n) = t_n - 1 + 2e^{-nh} = t_n - 1 + 2\big(e^{-h}\big)^n\mathclose{\text{.}} So yn<y(tn)y_n < y(t_n) exactly when (1−h)n<(e−h)n.(1 - h)^n < \big(e^{-h}\big)^n\mathclose{\text{.}} Now 1+x≤ex1 + x \le e^x for every x,x\mathclose{\text{,}} with equality only at x=0:x = 0\mathclose{\text{:}} the graph of exe^x is concave up, so it lies above its tangent line y=1+xy = 1 + x at 0, touching it only there. With x=−h,x = -h\mathclose{\text{,}} and 0<h<1,0 < h < 1\mathclose{\text{,}} this gives 0<1−h<e−h.0 < 1 - h < e^{-h}\mathclose{\text{.}} Raising both sides to the power n≥1n \ge 1 keeps the inequality, because both sides are positive. So every approximation is below the exact value, for the reason that Example 13.6 gave: a curve that is concave up lies above its tangent lines. In particular, Euler’s approximation 1+2(1−2n)n1 + 2\big(1 - \tfrac2n\big)^n to y(2)y(2) is below 1+2e−21 + 2e^{-2} for every n≥3.n \ge 3\mathclose{\text{.}}

Exercise 13.11★★★Air resistance proportional to v2v^2

For fast bodies, air resistance is closer to proportional to v2.v^2\mathclose{\text{.}} Suppose that a body falling from rest satisfies v′=9.8−v2245,v' = 9.8 - \dfrac{v^2}{245}\mathclose{\text{,}} v(0)=0v(0) = 0 (hypothetical numbers).

  • (a) Find the terminal velocity.
  • (b) Solve the equation with partial fractions, and show that v=49tanh⁡(t/5).v = 49\tanh(t/5)\mathclose{\text{.}}
  • (c) How long does the body take to reach 95% of its terminal velocity? Compare with Exercise 13.6, where the resistance was 0.2v0.2v and the terminal velocity also 49 m/s.
Show solution✓ Checked

(a) v′=0v' = 0 when v2=9.8⋅245=2401,v^2 = 9.8 \cdot 245 = 2401\mathclose{\text{,}} at the terminal velocity v=49v = 49 m/s.

(b) Write v′=2401−v2245.v' = \dfrac{2401 - v^2}{245}\mathclose{\text{.}} The solution starts at 0, below the equilibrium 49, so 0≤v<490 \le v < 49 for t≥0t \ge 0 (it rises, since v′>0v' > 0 there, and cannot cross the equilibrium), and you may separate:

∫dv2401−v2=∫dt245.\int\frac{dv}{2401 - v^2} = \int\frac{dt}{245}.

By partial fractions, 12401−v2=1(49−v)(49+v)=198(149−v+149+v),\dfrac{1}{2401 - v^2} = \dfrac{1}{(49 - v)(49 + v)} = \dfrac{1}{98}\Big(\dfrac{1}{49 - v} + \dfrac{1}{49 + v}\Big)\mathclose{\text{,}} so the left side is

198(−ln⁡(49−v)+ln⁡(49+v))=198ln⁡49+v49−v.\begin{aligned} &\frac{1}{98}\Big(-\ln(49 - v) + \ln(49 + v)\Big) \\ &\quad= \frac{1}{98}\ln\frac{49 + v}{49 - v}. \end{aligned}

At t=0,t = 0\mathclose{\text{,}} v=0v = 0 and both sides are 0, so the constant is 0, and ln⁡49+v49−v=98t245=2t5.\ln\dfrac{49 + v}{49 - v} = \dfrac{98t}{245} = \dfrac{2t}{5}\mathclose{\text{.}} Hence 49+v49−v=e2t/5,\dfrac{49 + v}{49 - v} = e^{2t/5}\mathclose{\text{,}} so 49+v=e2t/5(49−v),49 + v = e^{2t/5}(49 - v)\mathclose{\text{,}} v(1+e2t/5)=49(e2t/5−1),v\big(1 + e^{2t/5}\big) = 49\big(e^{2t/5} - 1\big)\mathclose{\text{,}} and, multiplying the top and the bottom by e−t/5,e^{-t/5}\mathclose{\text{,}}

v=49 e2t/5−1e2t/5+1=49 et/5−e−t/5et/5+e−t/5=49tanh⁡t5,\begin{aligned} v &= 49\,\frac{e^{2t/5} - 1}{e^{2t/5} + 1} \\ &= 49\,\frac{e^{t/5} - e^{-t/5}}{e^{t/5} + e^{-t/5}} \\ &= 49\tanh\frac{t}{5}, \end{aligned}

since tanh⁡x=sinh⁡xcosh⁡x=ex−e−xex+e−x\tanh x = \dfrac{\sinh x}{\cosh x} = \dfrac{e^x - e^{-x}}{e^x + e^{-x}} (Module 6).

(c) tanh⁡t5=0.95\tanh\dfrac t5 = 0.95 means e2t/5−1e2t/5+1=0.95,\dfrac{e^{2t/5} - 1}{e^{2t/5} + 1} = 0.95\mathclose{\text{,}} so e2t/5=1.950.05=39e^{2t/5} = \dfrac{1.95}{0.05} = 39 and

t=52ln⁡39≈9.16 seconds,t = \frac52\ln 39 \approx 9.16 \text{ seconds},

against 15.0 seconds in Exercise 13.6. For 0<v<49,0 < v < 49\mathclose{\text{,}} v2245<49v245=0.2v:\dfrac{v^2}{245} < \dfrac{49v}{245} = 0.2v\mathclose{\text{:}} at every speed below the terminal velocity the quadratic resistance is the weaker of the two, so this body speeds up faster.

Exercise 13.12★★★An RC circuit as a filter

An RC circuit with R=1R = 1 ohm and C=1C = 1 farad, so that its time constant is RC=1RC = 1 second, is driven by the alternating voltage sin⁡t\sin t volts. Its charge satisfies q′+q=sin⁡t,q' + q = \sin t\mathclose{\text{,}} and q(0)=0.q(0) = 0\mathclose{\text{.}}

  • (a) Solve the initial value problem.
  • (b) Show that once the term with e−te^{-t} has died away, q(t)=12sin⁡(t−π4):q(t) = \dfrac{1}{\sqrt2}\sin\Big(t - \dfrac{\pi}{4}\Big)\mathclose{\text{:}} a wave of the same frequency as the input, smaller by the factor 12\tfrac{1}{\sqrt2} and delayed by π4.\tfrac{\pi}{4}\mathclose{\text{.}}
Show solution✓ Checked

(a) The equation is in standard form with p=1,p = 1\mathclose{\text{,}} so μ=et\mu = e^t and (etq)′=etsin⁡t.(e^tq)' = e^t\sin t\mathclose{\text{.}} Integrate by parts twice (Module 11). Let J=∫etsin⁡t dt.J = \int e^t\sin t\,dt\mathclose{\text{.}} With u=sin⁡tu = \sin t and dv=et dt,dv = e^t\,dt\mathclose{\text{,}} J=etsin⁡t−∫etcos⁡t dt;J = e^t\sin t - \int e^t\cos t\,dt\mathclose{\text{;}} and with u=cos⁡t,u = \cos t\mathclose{\text{,}} ∫etcos⁡t dt=etcos⁡t+∫etsin⁡t dt=etcos⁡t+J.\int e^t\cos t\,dt = e^t\cos t + \int e^t\sin t\,dt = e^t\cos t + J\mathclose{\text{.}} So J=etsin⁡t−etcos⁡t−J,J = e^t\sin t - e^t\cos t - J\mathclose{\text{,}} and

∫etsin⁡t dt=et(sin⁡t−cos⁡t)2+C.\begin{aligned} &\int e^t\sin t\,dt \\ &\quad= \frac{e^t(\sin t - \cos t)}{2} + C. \end{aligned}

Then etq=12et(sin⁡t−cos⁡t)+C,e^tq = \tfrac12 e^t(\sin t - \cos t) + C\mathclose{\text{,}} so q=12(sin⁡t−cos⁡t)+Ce−t,q = \tfrac12(\sin t - \cos t) + Ce^{-t}\mathclose{\text{,}} and q(0)=−12+C=0q(0) = -\tfrac12 + C = 0 gives C=12:C = \tfrac12\mathclose{\text{:}}

q(t)=sin⁡t−cos⁡t+e−t2.q(t) = \frac{\sin t - \cos t + e^{-t}}{2}.

(b) After a few seconds e−te^{-t} is negligible, and q≈12(sin⁡t−cos⁡t).q \approx \tfrac12(\sin t - \cos t)\mathclose{\text{.}} By the addition formula of Section 1.4, sin⁡(t−π4)=sin⁡tcos⁡π4−cos⁡tsin⁡π4,\sin\big(t - \tfrac\pi4\big) = \sin t\cos\tfrac\pi4 - \cos t\sin\tfrac\pi4\mathclose{\text{,}} and cos⁡π4=sin⁡π4=12,\cos\tfrac\pi4 = \sin\tfrac\pi4 = \tfrac{1}{\sqrt2}\mathclose{\text{,}} so

sin⁡(t−π4)=sin⁡t−cos⁡t2,\sin\Big(t - \frac\pi4\Big) = \frac{\sin t - \cos t}{\sqrt2},

so 12(sin⁡t−cos⁡t)=12sin⁡(t−π4).\tfrac12(\sin t - \cos t) = \tfrac{1}{\sqrt2}\sin\big(t - \tfrac\pi4\big)\mathclose{\text{.}} The input has amplitude 1; the response has amplitude 12≈0.707\tfrac{1}{\sqrt2} \approx 0.707 and lags an eighth of a period behind. With the input sin⁡ωt\sin\omega t the same steps give the amplitude 1/1+ω2:1/\sqrt{1 + \omega^2}\mathclose{\text{:}} the faster the input oscillates, the smaller the response. That is what a low-pass filter does.

12

Check yourself

1
The order of the differential equation y′′+(y′)3=ty'' + (y')^3 = t is
2
Which function is the solution of y′=2yy' = 2y with y(0)=3?y(0) = 3\mathclose{\text{?}}
3
In the direction field of y′=t−y,y' = t - y\mathclose{\text{,}} the segment at the point (2,−1)(2, -1) has slope
4
The equilibria of y′=y(2−y)y' = y(2 - y) are
5
Euler’s method with h=0.5h = 0.5 for y′=y,y' = y\mathclose{\text{,}} y(0)=1,y(0) = 1\mathclose{\text{,}} approximates y(1)y(1) by
6
With step h=0.1,h = 0.1\mathclose{\text{,}} Euler’s method has error 0.04 at t=2.t = 2\mathclose{\text{.}} With h=0.05h = 0.05 its error at t=2t = 2 is about
7
An integrating factor for y′+3y=ety' + 3y = e^t is
8
The general solution of y′′+2y′+5y=0y'' + 2y' + 5y = 0 is
Finished this module?