Flow Lab

Syllabus / Module 3: First-Order ODEs

Lesson 3.1

What Is a Differential Equation?

Rates of change as laws of nature; order, linearity, ODE vs PDE; what it means to be a solution; initial value problems; families of solutions.

Written byClaude Sonnet

🌊
Why this matters for simulation: Navier–Stokes is a statement about rates of change of momentum — the same idea as Newton's 2nd law, F = m dv/dt.

By the end of this lesson you can…

  • Write a physical law (Newton's second law, cooling, decay, growth, drag) as an equation relating a quantity to its own rate of change.
  • Classify an equation as an ODE or a PDE, state its order, and decide whether it is linear or nonlinear.
  • Verify that a proposed function is a solution by substituting it into the equation, and compute a numerical residual when you cannot do it by hand.
  • Explain a general solution as a family of curves with one free constant per order, and use an initial condition to pick out one member.
  • Run the modeling cycle (assumptions, equation, solve, validate) on a simple model and say which step failed when the prediction does not match reality.
On this page
·
  1. Laws of nature are statements about rates of change
  2. ODEs, PDEs, and order
  3. Order
  4. Linear or nonlinear?
  5. What does it mean to be a solution?
  6. General solutions: a whole family of curves
  7. Initial value problems: choosing one curve
  8. The modeling cycle
  9. Exercise: check a solution and classify an equation
  10. Where this goes next
  11. Key Takeaways

You already know how to solve differential equations, in the sense that matters for a simulator. You have written Euler’s method and three of its variants, you have written RK4, and you have written RK45 with step-size control. You hand each of them a function f(t,y)f(t, y) and a starting value and they march forward. What none of those programs ever told you is what you are actually marching toward: what object is the solver approximating, when is there exactly one, and how would you recognize it if someone handed you a formula? This lesson builds that missing theory. It is the first lesson of the module on first-order ODEs, and its main habit is one you will use in every lesson after it: put the analytic solution next to the numerical one. Your solvers are the experiment; the theory tells you what the experiment should show.

The reason this matters for the fluid simulator you want to build is simple. Every law that governs air and water is a statement about a rate of change: how fast momentum, mass, heat or concentration changes at a point. We met the language for rates of change in space in 2.1 Functions of Several Variables & Partial Derivatives. Here we start with the simplest case, rates of change in time of a single number, and get the vocabulary straight: ODE, PDE, order, linear, solution, family, initial value problem.

▶ Video Rates of change as laws, solutions as families of curves, and an initial condition picking onecaptions only
Transcript
  1. You have written Euler, R K four and R K forty-five. Each one marches forward, but toward what? Today we name the thing your solvers are approximating.
  2. Almost no law of nature tells you what a quantity is. It tells you how fast the quantity is changing, given the situation it is in. Force sets the rate of change of velocity. The gap between a cup and the room sets how fast it cools. The number of rabbits sets how fast the rabbits multiply.
  3. Notice what every one of these has in common. The unknown is not a number. It is a whole function of time, and the equation ties that function to its own derivative. That is the definition of a differential equation.
  4. And this is the fluids connection. The equation that governs every flow you want to simulate is Newton's second law written per unit volume: density times the acceleration of a blob of fluid, equal to the sum of the forces on it, pressure, viscosity and gravity. It is the same idea as F equals m d v d t.
  5. If the unknown depends on one variable, the equation has only ordinary derivatives, and we call it an O D E. A cup of coffee has one temperature. If the unknown depends on several variables, there are partial derivatives, and it is a P D E. A rod has a temperature at every point along it. We spend this module on O D Es first, because they are the engine inside a P D E solver.
  6. The order of an equation is the order of the highest derivative in it, shown here in amber. One prime, order one. Two primes, order two. An equation of order n leaves n free constants, and needs n pieces of starting data. That is why your solvers carry a state vector as long as the order.
  7. Next, linear versus nonlinear. An equation is linear when the unknown and its derivatives appear only to the first power, multiplied by functions of t, and added up. These two, in green, are linear. The coefficients can be as wild as you like.
  8. These three, in red, are nonlinear. The unknown is squared, or multiplied by its own derivative, or sits inside a sine. This matters, because linear equations can be built from simple pieces by superposition, and nonlinear ones cannot. In the Navier Stokes equation, the one nonlinear term is the advection term, and it is the source of turbulence.
  9. How do you check that a function really is a solution? You substitute. Here is the equation y prime equals two y, and a candidate, C times e to the two t.
  10. Differentiate the candidate, and the left side is two C e to the two t. Put the candidate into the right side, and it is two C e to the two t again. The two sides match for every t and every C, so it is a solution.
  11. Now a function that fails. Try y equals t squared in the same equation. The left side is two t, the right side is two t squared.
  12. They agree at t equals zero, and again at t equals one. Two lucky points. But at t equals two, the left side is four and the right side is eight. A solution has to make the equation true for every t on the interval, not at a couple of points.
  13. Here is the visual heart of the lesson. The equation y prime equals y, the growth law with rate constant one, is solved by y equals C e to the t. Watch what happens as we turn the dial on C.
  14. Make C bigger, and the curve climbs faster. Take C to zero, and it flattens onto the axis, which is a solution too. Make C negative, and the whole curve flips below the axis. Every one of these curves is a solution of the very same equation.
  15. So the equation does not have one solution. It has a whole one-parameter family, filling the plane, with one free constant. Differentiating kills constants, so undoing a derivative cannot recover them. That is where the constant comes from, and an equation of order n leaves n of them.
  16. A family of solutions is not yet a prediction. To say what a quantity will actually do, you must say where it starts. An initial condition names one point, t zero, y zero, in the plane.
  17. Of all the curves in the family, exactly one passes through that point. Fix the point, and you fix the constant, C equals y zero times e to the minus t zero, about point nine one. That is an initial value problem: an equation plus a starting point, and it picks out a single curve.
  18. Now the habit this whole module is built on: put the analytic solution next to a numerical one. That amber curve is the exact solution of the initial value problem. Your Euler solver, with a step of one half, takes these red steps.
  19. Every red step lands below the curve, and the gap grows. By t equals two, Euler is off by about one point seven. Run R K four at the very same step size, in green, and the points sit on the curve, with an error of about three thousandths.
  20. To recap. A differential equation relates an unknown function to its own derivatives. Its general solution is a whole family of curves, and an initial condition picks out one. Euler, R K four and R K forty-five are all ways of computing that one curve.
  21. Next, we turn the equation itself into a picture, with direction fields, and watch Euler's method walk along them.

Laws of nature are statements about rates of change

Almost nothing in physics tells you directly what a quantity is. It tells you how the quantity changes, given the situation it is currently in. That is a much easier thing to know. You cannot write down, from first principles, the temperature of a cup of coffee at 3:17 pm. But you can say how fast it is cooling right now, given how much hotter it is than the room. Each law below is of that kind.

Newton’s second law. A body of mass mm with position x(t)x(t) and velocity v=x′v = x' obeys

m dvdt=F.m\,\frac{dv}{dt} = F .

The force depends on the situation (a spring gives F=−kxF = -kx, gravity gives F=−mgF = -mg) and the equation turns it into a rule for how the velocity changes. Newton’s own statement in the Principia says, in words, that a change of motion is proportional to the force impressed. Reading “motion” as momentum mvmv gives F=d(mv)dtF = \frac{d(mv)}{dt} in modern notation, a statement about the rate of change of momentum. Keep that form in mind; it comes back below.

Newton’s law of cooling. An object at temperature TT in surroundings at temperature TenvT_{\text{env}} loses heat at a rate proportional to the temperature difference:

dTdt=−k (T−Tenv),k>0.\frac{dT}{dt} = -k\,(T - T_{\text{env}}), \qquad k \gt 0 .

The sign says: hotter than the room means T′<0T' \lt 0 (cooling), colder than the room means T′>0T' \gt 0 (warming). The proportionality is an assumption, a good one for small temperature differences.

Exponential growth. If every individual in a population PP reproduces at the same per-capita rate rr, then the total growth rate is proportional to the number of individuals:

dPdt=r P.\frac{dP}{dt} = r\,P .

Radioactive decay. Each nucleus decays independently, with a fixed probability per unit time λ\lambda, so the expected rate of loss is proportional to how many are left:

dNdt=−λ N.\frac{dN}{dt} = -\lambda\,N .

Drag. A skydiver of mass mm falling with velocity vv is pulled down by gravity and slowed by a drag force. For modest speeds, take the drag to be proportional to the speed, c vc\,v:

m dvdt=mg−c v.m\,\frac{dv}{dt} = m g - c\,v .

Notice what these have in common. The unknown is a function (T(t)T(t), P(t)P(t), N(t)N(t), v(t)v(t)), and the equation relates the function to its own derivative. That is the definition we want.

Worked example: the drag law reads off a speed limit. Take m=80m = 80 kg, g=9.8g = 9.8 m/s², c=16c = 16 kg/s. Dividing by mm:

v′=9.8−0.2 v.v' = 9.8 - 0.2\,v .

You can learn a lot without solving anything. When v=0v = 0 the right side is 9.89.8, so the skydiver accelerates at gg. As vv grows the right side shrinks, and it hits zero at v=9.8/0.2=49v = 9.8/0.2 = 49 m/s. At that speed v′=0v' = 0, so the velocity stops changing. That is the terminal velocity, and we found it by asking where the rate of change vanishes. We will return to this model with a full solution in the problems below.

ODEs, PDEs, and order

All five laws above have one independent variable, time. A differential equation whose unknown depends on one independent variable, so that it involves only ordinary derivatives, is an ordinary differential equation (ODE). If the unknown depends on several variables and the equation contains partial derivatives, it is a partial differential equation (PDE).

The classic first PDE is the heat equation. Let u(x,t)u(x, t) be the temperature at position xx along a rod at time tt:

ut=α uxx.u_t = \alpha\,u_{xx} .

It says that, at each position, the temperature rises where the profile curves upward and falls where it curves downward. You can read that sentence off the subscripts because of 2.1 Functions of Several Variables & Partial Derivatives. The cup of coffee has a single temperature T(t)T(t) and obeys an ODE; the rod has a temperature at every point and obeys a PDE.

Why do we spend a whole module on ODEs before touching PDEs? Two reasons. First, the tools (families of solutions, initial conditions, linearity, stability) are the same, and they are easier to see with one variable. Second, and this is the bridge to your simulator: when you put a grid of NN points along the rod and replace uxxu_{xx} with the stencil (ui+1−2ui+ui−1)/h2(u_{i+1} - 2u_i + u_{i-1})/h^2, you get

duidt=α ui+1−2ui+ui−1h2,i=1,…,N,\frac{du_i}{dt} = \alpha\,\frac{u_{i+1} - 2u_i + u_{i-1}}{h^2}, \qquad i = 1, \dots, N,

which is a system of NN coupled ODEs, one per grid cell. This is the method of lines, and it is how a time-stepping PDE solver is organized: discretize space, and hand the resulting ODEs to a time integrator like RK4. We build that in 10.2 Explicit Methods for the Heat Equation. So an ODE solver is the engine inside a PDE solver, and understanding ODEs is not a detour.

Order

The order of a differential equation is the order of the highest derivative that appears.

EquationOrderWhy
y′=−3yy' = -3y1only y′y'
m x′′=−kxm\,x'' = -kx2highest derivative is x′′x''
(y′)3+t y′′=0(y')^3 + t\,y'' = 02y′′y'' is the highest derivative; the exponent 33 on y′y' is a power, not an order
y′′′=etyy''' = e^t y3highest derivative is y′′′y'''

Order tells you how much information it takes to pin down a solution. Integrating once introduces one constant of integration, so an order-nn equation leaves nn free constants and needs nn pieces of starting data: y(t0)y(t_0), then y′(t0)y'(t_0), and so on up to y(n−1)(t0)y^{(n-1)}(t_0). You have already met this in code. A second-order equation such as y′′=−4yy'' = -4y becomes a first-order system by naming the derivative, v=y′v = y':

y′=v,v′=−4y.\begin{aligned} y' &= v ,\\ v' &= -4y . \end{aligned}

Your solvers take a state vector, and the length of that vector is the order. Whenever you simulated something with second derivatives (a spring, a pendulum, a falling body under gravity), the state was position and velocity, because the order was two. We will treat such systems properly in 7.1 Systems & State Space; the rest of this module stays with first-order equations y′=f(t,y)y' = f(t, y).

✅ Concept check

What is the order of the equation $(y')^3 + t\,y'' = 0$?

Linear or nonlinear?

Within ODEs, the most important split is between linear and nonlinear equations. An ODE is linear if it can be written in the form

an(t) y(n)+an−1(t) y(n−1)+⋯+a1(t) y′+a0(t) y=g(t),a_n(t)\,y^{(n)} + a_{n-1}(t)\,y^{(n-1)} + \cdots + a_1(t)\,y' + a_0(t)\,y = g(t),

where the coefficients aka_k and the right side gg may be any functions of tt, but the unknown yy and its derivatives appear only to the first power, multiplied by functions of tt, and added together. Anything else is nonlinear: yy or its derivatives squared, multiplied by each other, or inside a function like sin⁡\sin or exp⁡\exp.

Classification drill, worked.

EquationOrderLinear?Reason
y′=kyy' = ky1lineary′y' and yy appear to the first power
y′+t2y=sin⁡ty' + t^2 y = \sin t1lineart2t^2 is a coefficient and sin⁡t\sin t is the forcing term g(t)g(t), neither involves yy
y′′+3y′+2y=ety'' + 3y' + 2y = e^t2linearconstant coefficients, forcing ete^t
y′=y2y' = y^21nonlineary2y^2
y y′=ty\,y' = t1nonlinearthe unknown multiplies its own derivative
y′′+sin⁡y=0y'' + \sin y = 02nonlinearthe unknown sits inside a sin⁡\sin (this is the pendulum)
y′=y(1−y)y' = y(1 - y)1nonlinearexpands to y−y2y - y^2

Why care? Because linear equations obey the principle of superposition. For a homogeneous linear equation (right side g=0g = 0), if y1y_1 and y2y_2 are solutions then so is c1y1+c2y2c_1 y_1 + c_2 y_2 for any constants. Here is the first-order proof. Suppose y1′+p(t) y1=0y_1' + p(t)\,y_1 = 0 and y2′+p(t) y2=0y_2' + p(t)\,y_2 = 0. Then

(c1y1+c2y2)′+p (c1y1+c2y2)=c1 (y1′+p y1)+c2 (y2′+p y2)=0.(c_1 y_1 + c_2 y_2)' + p\,(c_1 y_1 + c_2 y_2) = c_1\,(y_1' + p\,y_1) + c_2\,(y_2' + p\,y_2) = 0 .

That one line is why linear problems are solvable by building blocks (eigenvectors, sines and cosines, Laplace transforms), and why most of this course is about linear equations and about approximating nonlinear ones by linear ones.

Superposition fails for nonlinear equations. The function y1=1/(1−t)y_1 = 1/(1-t) solves y′=y2y' = y^2, because y1′=1/(1−t)2=y12y_1' = 1/(1-t)^2 = y_1^2. But take 2y1=2/(1−t)2y_1 = 2/(1-t): its derivative is 2/(1−t)22/(1-t)^2, while its square is 4/(1−t)24/(1-t)^2. These are not equal, so 2y12y_1 is not a solution. Notice also what y1y_1 does: it goes to infinity at t=1t = 1, even though the equation y′=y2y' = y^2 contains nothing singular. Nonlinear equations can blow up in finite time, and their solutions need not exist for all tt. Linear equations with nice coefficients never do that.

✅ Concept checkselect all that apply

Select every equation that is NONlinear.

What does it mean to be a solution?

A solution of a differential equation on an interval II is a function with enough derivatives that, when you substitute it for the unknown, the equation becomes a true statement for every tt in II. Verifying a solution is therefore pure substitution: compute the derivatives of the candidate, plug them in, and simplify until both sides match.

Example 1. Is y=Ce2ty = Ce^{2t} a solution of y′=2yy' = 2y, for any constant CC? Compute y′=2Ce2ty' = 2Ce^{2t}. The right side is 2y=2Ce2t2y = 2Ce^{2t}. They match for every tt and every CC, so yes.

Example 2. Is y=t+1+Cety = t + 1 + Ce^{t} a solution of y′=y−ty' = y - t? Here y′=1+Cety' = 1 + Ce^t, and y−t=(t+1+Cet)−t=1+Cety - t = (t + 1 + Ce^t) - t = 1 + Ce^t. Equal, so yes, for every CC.

Example 3: a function that is not a solution. Try y=t2y = t^2 in y′=2yy' = 2y. The left side is y′=2ty' = 2t, the right side is 2y=2t22y = 2t^2. They agree at t=0t = 0 (both 00) and at t=1t = 1 (both 22), but at t=2t = 2 the left side is 44 and the right is 88. Agreeing at one or two points is not enough: the equation has to hold identically on the whole interval.

Example 4: a second-order equation. Check that y=Acos⁡2t+Bsin⁡2ty = A\cos 2t + B\sin 2t solves y′′+4y=0y'' + 4y = 0 for any constants AA and BB. We have y′=−2Asin⁡2t+2Bcos⁡2ty' = -2A\sin 2t + 2B\cos 2t and y′′=−4Acos⁡2t−4Bsin⁡2t=−4yy'' = -4A\cos 2t - 4B\sin 2t = -4y, so y′′+4y=0y'' + 4y = 0. ✓ Two free constants for a second-order equation, as promised by the order.

The same test works when you cannot do the algebra by hand, which is nearly always the case for a candidate that came out of a computer. Define the residual of a candidate yc(t)y_c(t) for the equation y′=f(t,y)y' = f(t, y) as

r(t)=yc′(t)−f(t,yc(t)).r(t) = y_c'(t) - f\big(t, y_c(t)\big).

A true solution has r(t)=0r(t) = 0 for every tt. For a candidate that is wrong, the residual measures how wrong. For example, yc=e3ty_c = e^{3t} in y′=2yy' = 2y has r(t)=3e3t−2e3t=e3tr(t) = 3e^{3t} - 2e^{3t} = e^{3t}, which is never zero. You can estimate yc′y_c' with a central difference (yc(t+h)−yc(t−h))/(2h)\big(y_c(t+h) - y_c(t-h)\big)/(2h), exactly the stencil from 2.1 Functions of Several Variables & Partial Derivatives. You will build this check yourself at the end of the lesson.

✅ Concept check

For the equation $y' = 2y$, the candidate $y_c(t) = e^{3t}$ has residual $r(t) = y_c' - 2y_c$. What is $r(0.5)$? (Give a number.)

General solutions: a whole family of curves

Look again at Example 1. The function y=Ce2ty = Ce^{2t} is a solution for every value of CC. The equation y′=2yy' = 2y does not have one solution; it has a whole one-parameter family. Is that all of them, or could there be others? For y′=kyy' = ky we can prove it. Multiply the equation by e−kte^{-kt} and rearrange:

ddt(y e−kt)=y′e−kt−k y e−kt=(y′−ky) e−kt=0.\frac{d}{dt}\Big(y\,e^{-kt}\Big) = y'e^{-kt} - k\,y\,e^{-kt} = (y' - ky)\,e^{-kt} = 0 .

A function whose derivative is zero everywhere on an interval is constant, so y e−kt=Cy\,e^{-kt} = C, that is, y=Cekty = Ce^{kt}. Every solution of y′=kyy' = ky is in the family and nothing else is. We call y=Cekty = Ce^{kt} the general solution. Choosing a particular value for CC gives a particular solution.

The simplest first-order equations show where the constant comes from. For y′=g(t)y' = g(t), with no yy on the right at all, integration gives y=∫g(t) dt+Cy = \int g(t)\,dt + C. The equation y′=2ty' = 2t has solutions y=t2+Cy = t^2 + C: all the parabolas, shifted up and down. Every one of them has the same slope 2t2t at the same value of tt, which is exactly what the equation demands. That is the whole story of the constant. Differentiating kills constants, so undoing a derivative can’t recover them, and each level of integration leaves one free.

An order-nn equation has an nn-parameter family, so the equation y′′+4y=0y'' + 4y = 0 has y=Acos⁡2t+Bsin⁡2ty = A\cos 2t + B\sin 2t, with two constants. One warning, to be developed in 3.3 Separable Equations: for nonlinear equations a single formula with one constant may miss some solutions. The logistic equation y′=y(1−y)y' = y(1-y) has the family y=1/(1+Ce−t)y = 1/(1 + Ce^{-t}), but the constant solution y=0y = 0 belongs to none of its members (it appears only in the limit C→∞C \to \infty).

The explorer below shows this directly. Pick an equation and the plot shows its slope field (the little arrows, drawn as short segments) and a family of exact solutions, one curve for each choice of the constant. Click anywhere to choose a starting point; the amber curve through it is the solution of the IVP described in the next section. The red dots are a numerical solution you can compare against it.

◆ Interactive Pick an ODE, click an initial condition, and compare the exact solution with a numerical one

Loading simulation…

Try these:

  1. On y′ = k y, drag the starting point up and down. The amber curve slides through the family, and the readout shows the constant CC changing. The slope arrows do not change at all: the equation is fixed, only the choice of solution moves.
  2. Switch to cooling. Every curve, whatever its start, bends toward the horizontal line y=2y = 2, the surrounding temperature. This is the equilibrium, where y′=0y' = 0.
  3. With the Euler method at h=0.5h = 0.5 on the growth equation, start above the axis. The red dots fall below the exact curve and drift further away. Now switch to RK4 at the same hh. The dots sit on the curve to within the width of the line. Decrease hh and watch Euler close the gap, slowly.
  4. Switch to the nonlinear y′ = y² with a positive start. The exact curve shoots to infinity at the finite time t0+1/y0t_0 + 1/y_0. With Euler at h=0.5h = 0.5 from (0,0.5)(0, 0.5) the exact solution is gone at t=2t = 2, yet the dots keep going, climbing past the top of the plot: the solver does not know about the blow-up. The readout reports that the numerical solution only becomes unbounded around t=3.5t = 3.5, long after the true solution ceased to exist.
  5. On logistic, click a point above y=1y = 1 and a point below y=0y = 0 and see what the two curves do, then click between 00 and 11.
✏️ Pen & paperClassify and count●○○

For each equation, state whether it is an ODE or a PDE, its order, and whether it is linear or nonlinear.

  1. y′+3y=t2y' + 3y = t^2
  2. θ′′+gLsin⁡θ=0\theta'' + \dfrac{g}{L}\sin\theta = 0
  3. ut+c ux=0u_t + c\,u_x = 0
  4. ut+u ux=ν uxxu_t + u\,u_x = \nu\,u_{xx}
  5. x2y′′−2xy′+2y=0x^2 y'' - 2x y' + 2y = 0
Show worked solution
  1. ODE, order 1, linear (forcing term t2t^2).
  2. ODE, order 2, nonlinear (the unknown θ\theta is inside a sine).
  3. PDE (unknown u(x,t)u(x,t), partial derivatives), order 1, linear. This is the advection equation, a profile moving at speed cc.
  4. PDE, order 2 (highest derivative is uxxu_{xx}), nonlinear because of the product u uxu\,u_x. This is Burgers’ equation, a one-dimensional cousin of Navier–Stokes with the same nonlinear advection term.
  5. ODE, order 2, linear. The coefficients x2x^2 and −2x-2x depend on the independent variable, which is allowed.

Initial value problems: choosing one curve

A family of solutions is not yet a prediction. If you want to know what a quantity will do, you need to say where it starts. An initial value problem (IVP) is a differential equation together with starting data:

y′=f(t,y),y(t0)=y0.y' = f(t, y), \qquad y(t_0) = y_0 .

Geometrically, the initial condition names a point (t0,y0)(t_0, y_0) in the plane, and the solution of the IVP is the one curve of the family that passes through that point. Algebraically it fixes the constant. In the sim above, this is the amber curve and the value of CC in the readout.

Worked example: finding CC. Solve y′=−2yy' = -2y with y(1)=3y(1) = 3. The general solution is y=Ce−2ty = Ce^{-2t}. Impose the condition:

3=Ce−2⋅1⟹C=3e2≈22.167.3 = Ce^{-2\cdot 1} \quad\Longrightarrow\quad C = 3e^{2} \approx 22.167 .

So y=3e2e−2t=3e−2(t−1)y = 3e^{2}e^{-2t} = 3e^{-2(t-1)}. Check: y(1)=3e0=3y(1) = 3e^0 = 3 ✓ and y′=−2yy' = -2y ✓. Note that CC is not the same as y0y_0; they coincide only when t0=0t_0 = 0.

Worked example: a second-order IVP. Solve y′′+4y=0y'' + 4y = 0 with y(0)=1y(0) = 1 and y′(0)=2y'(0) = 2. Two constants need two conditions. From y=Acos⁡2t+Bsin⁡2ty = A\cos 2t + B\sin 2t we get y(0)=Ay(0) = A, so A=1A = 1, and y′(0)=2By'(0) = 2B, so B=1B = 1:

y=cos⁡2t+sin⁡2t.y = \cos 2t + \sin 2t .

Check: y(0)=1y(0) = 1 ✓, y′(t)=−2sin⁡2t+2cos⁡2ty'(t) = -2\sin 2t + 2\cos 2t so y′(0)=2y'(0) = 2 ✓.

✅ Concept check

The general solution of $y' = -2y$ is $y = Ce^{-2t}$. For the initial condition $y(1) = 3$, what is $C$? (Give a number.)

Does every IVP have a solution, and is it unique? Usually yes, when ff is reasonably well behaved: through each point of the plane passes exactly one solution curve, and curves never cross. But “usually” hides interesting exceptions, and they matter for numerical work. We study them carefully in 3.7 Existence & Uniqueness.

Let us do that. Take the IVP y′=y−ty' = y - t, y(0)=0.5y(0) = 0.5. From Example 2, the general solution is y=t+1+Cety = t + 1 + Ce^t, and y(0)=1+C=0.5y(0) = 1 + C = 0.5 gives C=−0.5C = -0.5, so the exact solution is y=t+1−0.5 ety = t + 1 - 0.5\,e^{t}. The cell runs Euler and RK4 at three step sizes and compares both to it at t=2t = 2.

🐍 PythonThe same IVP, analytic next to numerical
⌘/Ctrl + Enter

Run it and read the two ratios in the output. Each time hh is halved, Euler’s error shrinks by a factor of about 1.81.8 to 1.91.9 (close to the 22 of a first-order method) and RK4’s by a factor of about 1515 (close to the 1616 of a fourth-order method), the orders you know from your own solvers. What the theory adds is that the thing they are converging to is a specific curve you can write down.

The modeling cycle

So far we have been handed the equations. Real work starts one step earlier. Modeling is a loop with four steps:

  1. Assumptions. Decide what matters and what you will ignore. Write it down in words.
  2. Equation. Translate the assumptions into a differential equation and its initial condition.
  3. Solve. Find the solution, analytically if possible, numerically otherwise.
  4. Validate. Compare the prediction with measurements. If they disagree, the problem is almost never the algebra; it is an assumption. Go back to step 1.

Worked example: a cooling cup. Assumptions: the coffee is well mixed (one temperature TT), the room stays at 20 ∘20\,^\circC, and heat loss is proportional to the temperature difference. Equation:

T′=−k (T−20),T(0)=90.T' = -k\,(T - 20), \qquad T(0) = 90 .

Solve: the general solution is T=20+Ce−ktT = 20 + Ce^{-kt} (Example 1 with a shift), and T(0)=90T(0) = 90 gives C=70C = 70. The constant kk is not known from first principles, so we calibrate it with one measurement. Suppose the coffee reads 70 ∘70\,^\circC after 55 minutes. Then 70=20+70e−5k70 = 20 + 70e^{-5k}, so e−5k=50/70=5/7e^{-5k} = 50/70 = 5/7 and k=ln⁡(1.4)/5≈0.0673k = \ln(1.4)/5 \approx 0.0673 per minute. Now the model makes predictions it can be tested on:

  • At t=10t = 10 min: T=20+70 (5/7)2=20+70⋅25/49≈55.7 ∘T = 20 + 70\,(5/7)^2 = 20 + 70\cdot 25/49 \approx 55.7\,^\circC.
  • The time to cool to 40 ∘40\,^\circC: 20+70e−kt=4020 + 70e^{-kt} = 40 gives e−kt=2/7e^{-kt} = 2/7, so t=ln⁡(3.5)/k≈18.6t = \ln(3.5)/k \approx 18.6 min.

Validate: put a thermometer in the cup. If it reads about 55.7 ∘55.7\,^\circC at ten minutes, the model is good. If it reads much higher, then some assumption is failing: perhaps evaporation cools the hot coffee faster at first, so the effective kk falls as the cup cools and the single calibrated kk overpredicts the cooling, or the room is warming. The algebra is not what went wrong; an assumption is. Notice that the same analytic formula serves both as the answer and as the way to check a numerical run with a step size of your choice.

Worked example: when the assumptions run out. The growth law P′=rPP' = rP with r=0.02r = 0.02 per year has P=P0ertP = P_0e^{rt}, which doubles every ln⁡2/0.02≈34.7\ln 2/0.02 \approx 34.7 years, forever. A real population cannot do that: the assumption “every individual reproduces at the same rate regardless of crowding” breaks down at large PP. The validation step flags it, and we revise the assumption: the per-capita rate falls as the population approaches a carrying capacity KK. That gives P′=rP(1−P/K)P' = rP(1 - P/K), the logistic equation, which is nonlinear, and which you can explore in the sim. We study it in 3.8 Autonomous Equations, Equilibria & Stability. Each trip around the cycle replaces a too-simple assumption with a better one.

✏️ Pen & paperVerify and fit●○○
  1. Show that y=e−t+t−1y = e^{-t} + t - 1 is a solution of y′+y=ty' + y = t.
  2. The general solution of y′+y=ty' + y = t is y=t−1+Ce−ty = t - 1 + Ce^{-t}. Find the solution with y(0)=3y(0) = 3.
Show worked solution
  1. y′=−e−t+1y' = -e^{-t} + 1. Then y′+y=(−e−t+1)+(e−t+t−1)=ty' + y = (-e^{-t} + 1) + (e^{-t} + t - 1) = t. ✓ (The e−te^{-t} terms cancel, and 1−1=01 - 1 = 0.)
  2. y(0)=−1+C=3y(0) = -1 + C = 3 gives C=4C = 4, so y=t−1+4e−ty = t - 1 + 4e^{-t}. Check: y′=1−4e−ty' = 1 - 4e^{-t}, and y′+y=1−4e−t+t−1+4e−t=ty' + y = 1 - 4e^{-t} + t - 1 + 4e^{-t} = t ✓, and y(0)=−1+4=3y(0) = -1 + 4 = 3 ✓.
✏️ Pen & paperA second-order IVP●●○

Check that y=C1et+C2e−2ty = C_1e^{t} + C_2e^{-2t} solves y′′+y′−2y=0y'' + y' - 2y = 0 for all constants. Then find the solution with y(0)=1y(0) = 1 and y′(0)=−1y'(0) = -1.

Show worked solution

y′=C1et−2C2e−2ty' = C_1e^t - 2C_2e^{-2t} and y′′=C1et+4C2e−2ty'' = C_1e^t + 4C_2e^{-2t}. So

y′′+y′−2y=(1+1−2) C1et+(4−2−2) C2e−2t=0.✓y'' + y' - 2y = (1 + 1 - 2)\,C_1e^t + (4 - 2 - 2)\,C_2e^{-2t} = 0 . \checkmark

The initial conditions give two equations: C1+C2=1C_1 + C_2 = 1 and C1−2C2=−1C_1 - 2C_2 = -1. Subtracting the second from the first: 3C2=23C_2 = 2, so C2=2/3C_2 = 2/3 and C1=1/3C_1 = 1/3. The solution is y=13et+23e−2ty = \tfrac13 e^{t} + \tfrac23 e^{-2t}. Check: y(0)=1y(0) = 1 ✓, and y′(0)=13−43=−1y'(0) = \tfrac13 - \tfrac43 = -1 ✓.

✏️ Pen & paperRadioactive decay●●○

Carbon-14 decays by N′=−λNN' = -\lambda N with half-life 57305730 years.

  1. Find λ\lambda.
  2. What fraction of the carbon-14 remains after 10 00010\,000 years?
  3. After how many years is only 10%10\% left?
Show worked solution

The general solution is N=N0e−λtN = N_0e^{-\lambda t}. The half-life TT is defined by N(T)=N0/2N(T) = N_0/2, so e−λT=1/2e^{-\lambda T} = 1/2 and λ=ln⁡2/T\lambda = \ln 2/T.

  1. λ=ln⁡2/5730≈1.21×10−4\lambda = \ln 2/5730 \approx 1.21\times 10^{-4} per year.
  2. N/N0=e−λt=2−t/T=2−10000/5730≈0.298N/N_0 = e^{-\lambda t} = 2^{-t/T} = 2^{-10000/5730} \approx 0.298, about 30%30\%.
  3. e−λt=0.1e^{-\lambda t} = 0.1 gives t=ln⁡10/λ=5730 log⁡210≈19 035t = \ln 10/\lambda = 5730\,\log_2 10 \approx 19\,035 years.
✏️ Pen & paperTerminal velocity●●●

The skydiver from earlier obeys v′=9.8−0.2 vv' = 9.8 - 0.2\,v with v(0)=0v(0) = 0.

  1. Verify that v(t)=49 (1−e−0.2t)v(t) = 49\,(1 - e^{-0.2t}) solves the IVP.
  2. How long does it take to reach 90%90\% of terminal velocity?
  3. Replace the drag by a quadratic law, v′=9.8−b v2v' = 9.8 - b\,v^2 (with b>0b \gt 0). Is this equation linear? What is its terminal velocity?
Show worked solution
  1. v′=49⋅0.2 e−0.2t=9.8 e−0.2tv' = 49\cdot 0.2\,e^{-0.2t} = 9.8\,e^{-0.2t}. Also 9.8−0.2v=9.8−9.8 (1−e−0.2t)=9.8 e−0.2t9.8 - 0.2v = 9.8 - 9.8\,(1 - e^{-0.2t}) = 9.8\,e^{-0.2t}. Equal ✓. And v(0)=49 (1−1)=0v(0) = 49\,(1 - 1) = 0 ✓.
  2. 49 (1−e−0.2t)=0.9⋅4949\,(1 - e^{-0.2t}) = 0.9\cdot 49 gives e−0.2t=0.1e^{-0.2t} = 0.1, so t=5ln⁡10≈11.5t = 5\ln 10 \approx 11.5 s. The number 5=m/c5 = m/c s is the time constant: after one time constant the speed is 49 (1−e−1)≈31.049\,(1 - e^{-1}) \approx 31.0 m/s, about 63%63\% of terminal.
  3. It is nonlinear because of the v2v^2 term. Terminal velocity is where v′=0v' = 0: 9.8=b v29.8 = b\,v^2, so vterm=9.8/bv_{\text{term}} = \sqrt{9.8/b}. Quadratic drag is the realistic law at higher speeds; its dependence on the fluid density is the topic of 3.5 Modeling with First-Order ODEs.

Exercise: check a solution and classify an equation

Now build the two tools of this lesson in code. You will write a function that decides numerically whether a candidate y(t)y(t) satisfies y′=f(t,y)y' = f(t, y), using the residual and a central difference. Then you will write a classifier that determines the order and linearity of an ODE it is given only as a Python function.

For the classifier, we describe an ODE in residual form F(t,y,y′,y′′)=0F(t, y, y', y'') = 0, passed in as a function F(t, y, yp, ypp). For example, y′=y2y' = y^2 is F = lambda t, y, yp, ypp: yp - y**2. Probing a function numerically works because of two facts from this lesson. The order is the highest derivative that FF actually depends on, so perturb one slot at a time and see whether FF changes. The ODE is linear exactly when FF is an affine function of (y,y′,y′′)(y, y', y'') for fixed tt, which means F(t,au⃗+(1−a)w⃗)=a F(t,u⃗)+(1−a) F(t,w⃗)F\big(t, a\vec u + (1-a)\vec w\big) = a\,F(t,\vec u) + (1-a)\,F(t,\vec w) for all choices of u⃗\vec u, w⃗\vec w and weight aa. That is superposition in disguise, and testing it at random points is enough to catch every nonlinearity in this lesson.

🧪 Coding exerciseExercise: residual check and ODE classifier
⌘/Ctrl + Enter

The classifier is the check you do by eye in the drill, turned into an algorithm: “does the unknown appear to the first power only?” becomes “does FF pass the superposition test?” Be a little suspicious of any numerical classifier: random probing can only fail to find a counterexample. For the functions in this lesson that is enough, but a function that is nonlinear only in some tiny region could slip through. That is a real limitation, and the reason computer-algebra systems classify ODEs symbolically.

The residual idea also lets you see the superposition failure from earlier numerically. The next cell tests scaling a solution, on a linear and on a nonlinear equation.

🐍 PythonSuperposition holds for linear ODEs and fails for nonlinear ones
⌘/Ctrl + Enter

Where this goes next

We now have the vocabulary: an ODE relates a function to its rates of change, the order says how many constants and initial conditions it takes, linearity decides whether superposition works, a solution makes the equation hold identically, and an initial condition picks one member out of the family. We have not yet said how to find solutions in general, other than guessing. In 3.2 Direction Fields & Euler's Method Revisited we turn the slope-field picture of this lesson into a method: sketching solution curves without solving, and reading Euler’s method as “follow the arrows”. Then 3.3 Separable Equations and 3.4 Linear First-Order Equations & Integrating Factors give the two systematic techniques that solve most first-order equations, and 3.7 Existence & Uniqueness answers the question “can I trust that an IVP has exactly one answer?”. Behind all of it, 4.1 Local Error, Global Error & Order returns to the solvers you already wrote and explains their error in terms of what you have learned here.

Key Takeaways

  • A differential equation relates an unknown function to its own derivatives. Physical laws (Newton’s second law, cooling, growth, decay, drag, Navier–Stokes) are statements about rates of change, which is easier to know than the quantity itself.
  • An ODE has one independent variable; a PDE has several and partial derivatives (the heat equation ut=αuxxu_t = \alpha u_{xx}). Discretizing space turns a PDE into a large system of ODEs (the method of lines), so ODE solvers are the engine of PDE solvers.
  • The order is the highest derivative present. An order-nn equation has nn free constants and needs nn initial conditions, which is also the length of the state vector in your solver.
  • An ODE is linear if the unknown and its derivatives enter only to the first power, with coefficients depending on tt alone. Linear equations obey superposition; nonlinear ones do not and can blow up in finite time (as y′=y2y' = y^2 does). The advection term in Navier–Stokes is the nonlinearity.
  • A solution makes the equation true identically on an interval, not just at a point. Check by substituting, or numerically by the residual yc′−f(t,yc)y_c' - f(t, y_c), which is blind to the initial condition and is not the same as the error.
  • The general solution is a family of curves with one constant per order (for y′=kyy' = ky it is CektCe^{kt}, and that is every solution). Nonlinear equations can have solutions outside a one-formula family.
  • An initial value problem adds y(t0)=y0y(t_0) = y_0 and picks out one curve through that point. It is exactly the input of an ODE solver, so whenever a closed-form solution exists you can put it beside the numerical one and measure the error.
  • The modeling cycle is assumptions, equation, solve, validate. When validation fails, suspect an assumption before suspecting the algebra or the solver.
Finished this lesson?

Mark it complete to track your progress (saved in this browser). Reading every section does this for you.

Where this leads

These later lessons build directly on this one: