Physics
Universitymathematical-methods

Ordinary Differential Equations

A systematic way to turn equations involving rates of change into functions we can calculate, classify, and connect directly to physical motion.

This entire site has been solving differential equations almost from its first page, without stopping to name the general subject. Newton's laws gave us F=maF=ma, which becomes a differential equation whenever the force depends on position, velocity, or time. The equation of simple harmonic motion,

mx¨=kx,m\ddot x=-kx,

is a differential equation. The pendulum equation is one too. So is the Schrödinger equation.

Yet in each first encounter, we took a suspiciously fortunate route: guess a function, often a cosine, differentiate it, substitute it into the equation, and discover that it works. That proves the guessed function is a solution, but it leaves an uncomfortable question. Where did the guess come from? If the answer were not a cosine, how would we know what to try?

That is the problem ordinary differential equations are meant to organize. An ordinary differential equation, or ODE, relates an unknown function of one independent variable to one or more of its derivatives. The aim is not to eliminate insight or cleverness. It is to replace a collection of lucky guesses with methods that tell us what forms the solutions must take.

Classifying an ODE

Before solving a differential equation, it helps to know what kind of object is in front of us. Three distinctions determine which methods are available.

Order

The order of a differential equation is the order of the highest derivative appearing in it. For example,

dydx+3y=0\frac{dy}{dx}+3y=0

is first-order, while

mx¨+kx=0m\ddot x+kx=0

is second-order because x¨=d2x/dt2\ddot x=d^2x/dt^2 is the highest derivative present.

The order also tells us how much initial information is generally needed to select one solution from the family of possible solutions. A first-order equation usually requires one initial condition, such as y(0)y(0). A second-order equation usually requires two, such as the initial position x(0)x(0) and initial velocity x˙(0)\dot x(0).

Linear and nonlinear

An ODE is linear if the unknown function and its derivatives appear only to the first power, are not multiplied by one another, and have coefficients that depend at most on the independent variable. A general second-order linear ODE has the form

a2(t)y¨+a1(t)y˙+a0(t)y=g(t).a_2(t)\ddot y+a_1(t)\dot y+a_0(t)y=g(t).

The equation

mx¨+kx=0m\ddot x+kx=0

is linear. By contrast,

θ¨+gLsinθ=0\ddot\theta+\frac{g}{L}\sin\theta=0

for an exact pendulum is nonlinear because sinθ\sin\theta is not a linear function of the unknown angle θ\theta. The small-angle approximation sinθθ\sin\theta\approx\theta turns it into a linear equation, which is precisely why the approximated pendulum becomes so much easier to solve.

Homogeneous and inhomogeneous

A linear ODE is homogeneous if every term contains the unknown function or one of its derivatives. Thus the simple-harmonic-motion equation

mx¨+kx=0m\ddot x+kx=0

is second-order, linear, and homogeneous.

A linear ODE is inhomogeneous if a leftover term does not contain the unknown function. A driven oscillator obeys

mx¨+kx=F(t),m\ddot x+kx=F(t),

where the prescribed external force F(t)F(t) makes the equation inhomogeneous. Physically, this distinction separates the system's free motion from its response to an external drive.

First-order linear equations

Consider the general first-order linear ODE

dydx+P(x)y=Q(x).\frac{dy}{dx}+P(x)y=Q(x).

The difficulty is that the left side is almost, but not quite, the derivative of a product. We would like to multiply the equation by some function μ(x)\mu(x) so that

μ(x)dydx+μ(x)P(x)y\mu(x)\frac{dy}{dx}+\mu(x)P(x)y

becomes one exact derivative. The product rule says

ddx[μ(x)y(x)]=μ(x)dydx+dμdxy.\frac{d}{dx}\left[\mu(x)y(x)\right] =\mu(x)\frac{dy}{dx}+\frac{d\mu}{dx}y.

The two expressions agree if

dμdx=P(x)μ(x).\frac{d\mu}{dx}=P(x)\mu(x).

Dividing by μ\mu and integrating,

1μdμdx=P(x),\frac{1}{\mu}\frac{d\mu}{dx}=P(x), 1μdμ=P(x)dx,\int\frac{1}{\mu}\,d\mu=\int P(x)\,dx, lnμ=P(x)dx.\ln|\mu|=\int P(x)\,dx.

An overall nonzero constant multiplying μ\mu makes no difference, so we choose the integrating factor

μ(x)=eP(x)dx.\mu(x)=e^{\int P(x)\,dx}.

Multiplying the original ODE by this factor gives

μdydx+μPy=μQ.\mu\frac{dy}{dx}+\mu Py=\mu Q.

Because dμ/dx=Pμd\mu/dx=P\mu, the left side is exactly

ddx(μy)=μQ.\frac{d}{dx}(\mu y)=\mu Q.

Now integrate both sides:

μ(x)y(x)=μ(x)Q(x)dx+C,\mu(x)y(x)=\int \mu(x)Q(x)\,dx+C,

and therefore

y(x)=1μ(x)[μ(x)Q(x)dx+C].y(x)=\frac{1}{\mu(x)}\left[\int \mu(x)Q(x)\,dx+C\right].

The integrating factor was engineered to make the product rule do the work for us.

Example: solving y+2y=exy'+2y=e^{-x}

Start with

dydx+2y=ex.\frac{dy}{dx}+2y=e^{-x}.

Here

P(x)=2,Q(x)=ex.P(x)=2, \qquad Q(x)=e^{-x}.

The integrating factor is

μ(x)=e2dx=e2x.\mu(x)=e^{\int 2\,dx}=e^{2x}.

Multiply every term in the equation by e2xe^{2x}:

e2xdydx+2e2xy=e2xex.e^{2x}\frac{dy}{dx}+2e^{2x}y=e^{2x}e^{-x}.

The right side simplifies to exe^x, while the left side is an exact derivative:

ddx(e2xy)=ex.\frac{d}{dx}\left(e^{2x}y\right)=e^x.

Integrating,

e2xy=exdx=ex+C.e^{2x}y=\int e^x\,dx=e^x+C.

Finally, divide by e2xe^{2x}:

y=ex+Ce2x.y=e^{-x}+Ce^{-2x}.

We can verify the result directly. Differentiating gives

dydx=ex2Ce2x.\frac{dy}{dx}=-e^{-x}-2Ce^{-2x}.

Then

dydx+2y=ex2Ce2x+2ex+2Ce2x=ex,\frac{dy}{dx}+2y =-e^{-x}-2Ce^{-2x}+2e^{-x}+2Ce^{-2x} =e^{-x},

as required. The term exe^{-x} is a particular response to the inhomogeneous term, while Ce2xCe^{-2x} is the general solution of the corresponding homogeneous equation y+2y=0y'+2y=0.

Second-order equations with constant coefficients

Now consider a second-order linear homogeneous ODE with constant coefficients:

ay¨+by˙+cy=0,a\ddot y+b\dot y+cy=0,

where aa, bb, and cc are constants and a0a\neq0.

Here the exponential function has a remarkable property: differentiating it does not produce a new kind of function. If

y=ert,y=e^{rt},

then

y˙=rert\dot y=re^{rt}

and

y¨=r2ert.\ddot y=r^2e^{rt}.

Substitute these into the differential equation:

ar2ert+brert+cert=0.ar^2e^{rt}+bre^{rt}+ce^{rt}=0.

Factor out erte^{rt}:

ert(ar2+br+c)=0.e^{rt}(ar^2+br+c)=0.

Since erte^{rt} is never zero, the remaining factor must vanish:

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

This is the characteristic equation. A problem involving derivatives has become an algebraic problem involving a quadratic polynomial.

Its roots are

r=b±b24ac2a.r=\frac{-b\pm\sqrt{b^2-4ac}}{2a}.

The discriminant

Δ=b24ac\Delta=b^2-4ac

separates the solutions into three qualitatively different cases.

Two distinct real roots

If Δ>0\Delta>0, the characteristic equation has two distinct real roots r1r_1 and r2r_2. The corresponding exponentials are linearly independent, so the general solution is

y(t)=C1er1t+C2er2t.y(t)=C_1e^{r_1t}+C_2e^{r_2t}.

Positive roots produce exponential growth; negative roots produce exponential decay. When both roots are negative, a displaced system can return to equilibrium without crossing it repeatedly.

One repeated real root

If Δ=0\Delta=0, both roots merge into

r=b2a.r=-\frac{b}{2a}.

The function erte^{rt} is one solution, but simply writing it twice does not produce two independent solutions. A second-order equation needs two independent solutions, and the second one is

tert.te^{rt}.

Thus the general solution is

y(t)=(C1+C2t)ert.y(t)=(C_1+C_2t)e^{rt}.

One way to understand the factor of tt is to imagine two distinct exponential solutions as their roots approach one another. Their difference, divided by the shrinking separation of the roots, approaches a derivative with respect to rr:

rert=tert.\frac{\partial}{\partial r}e^{rt}=te^{rt}.

When the two roots merge, this limiting procedure supplies the missing independent solution.

Complex conjugate roots

If Δ<0\Delta<0, the roots come as a complex conjugate pair

r=α±iβ.r=\alpha\pm i\beta.

The exponential solutions are

e(α+iβ)tande(αiβ)t.e^{(\alpha+i\beta)t} \qquad\text{and}\qquad e^{(\alpha-i\beta)t}.

Euler's formula,

eiβt=cos(βt)+isin(βt),e^{i\beta t}=\cos(\beta t)+i\sin(\beta t),

lets us combine these into two real solutions:

eαtcos(βt)andeαtsin(βt).e^{\alpha t}\cos(\beta t) \qquad\text{and}\qquad e^{\alpha t}\sin(\beta t).

Therefore the general real solution is

y(t)=eαt[C1cos(βt)+C2sin(βt)].y(t)=e^{\alpha t}\left[C_1\cos(\beta t)+C_2\sin(\beta t)\right].

The imaginary part of the root produces oscillation. The real part controls the envelope: α<0\alpha<0 gives a decaying oscillation, α=0\alpha=0 gives an undamped oscillation, and α>0\alpha>0 gives a growing oscillation.

Three small graphs side by side showing the three qualitatively different behaviors of a second-order linear ODE solution: pure exponential growth or decay for real roots, oscillation for purely imaginary roots, and a decaying oscillation (spiral) for complex roots with a negative real part.

The roots of one quadratic decide the motion: real roots give exponential behavior, imaginary roots give oscillation, and complex roots combine an exponential envelope with an oscillation.

Why the cosine appears in simple harmonic motion

For simple harmonic motion, the equation is

mx¨+kx=0.m\ddot x+kx=0.

Comparing it with

ay¨+by˙+cy=0,a\ddot y+b\dot y+cy=0,

we identify

a=m,b=0,c=k.a=m, \qquad b=0, \qquad c=k.

The characteristic equation is

mr2+k=0.mr^2+k=0.

Therefore

r2=km,r^2=-\frac{k}{m},

and the roots are

r=±ikm.r=\pm i\sqrt{\frac{k}{m}}.

Defining

ω=km,\omega=\sqrt{\frac{k}{m}},

we have

r=±iω.r=\pm i\omega.

These purely imaginary roots produce the real general solution

x(t)=C1cos(ωt)+C2sin(ωt).x(t)=C_1\cos(\omega t)+C_2\sin(\omega t).

Equivalently, the constants can be repackaged as an amplitude and phase:

x(t)=Acos(ωt+ϕ).x(t)=A\cos(\omega t+\phi).

This is the rigorous reason the cosine guess used on the simple-harmonic-motion page worked. It was not luck. For this particular differential equation, the characteristic roots are necessarily imaginary, and Euler's formula necessarily turns their exponentials into sines and cosines.

Worked example

A damped harmonic oscillator obeys mx¨+bx˙+kx=0m\ddot x+b\dot x+kx=0. Solve the equation for m=1 kgm=1\text{ kg}, b=4 kg/sb=4\text{ kg/s}, and k=3 N/mk=3\text{ N/m}, then interpret the resulting motion. (click to reveal the solution)

Substituting the parameters: begin with

mx¨+bx˙+kx=0.m\ddot x+b\dot x+kx=0.

Using m=1m=1, b=4b=4, and k=3k=3 gives

x¨+4x˙+3x=0.\ddot x+4\dot x+3x=0.

Setting up the characteristic equation: try

x=ert.x=e^{rt}.

Then

x˙=rert\dot x=re^{rt}

and

x¨=r2ert.\ddot x=r^2e^{rt}.

Substitution gives

r2ert+4rert+3ert=0.r^2e^{rt}+4re^{rt}+3e^{rt}=0.

Factor out the nonzero exponential:

ert(r2+4r+3)=0.e^{rt}(r^2+4r+3)=0.

Therefore the characteristic equation is

r2+4r+3=0.r^2+4r+3=0.

Finding the roots: factor the quadratic:

r2+4r+3=(r+1)(r+3).r^2+4r+3=(r+1)(r+3).

Thus

(r+1)(r+3)=0,(r+1)(r+3)=0,

so the two distinct roots are

r1=1 s1,r2=3 s1.r_1=-1\text{ s}^{-1}, \qquad r_2=-3\text{ s}^{-1}.

The same result follows from the quadratic formula:

r=4±424(1)(3)2(1)=4±16122=4±22,r=\frac{-4\pm\sqrt{4^2-4(1)(3)}}{2(1)} =\frac{-4\pm\sqrt{16-12}}{2} =\frac{-4\pm2}{2},

which gives r=1 s1r=-1\text{ s}^{-1} and r=3 s1r=-3\text{ s}^{-1}.

Writing the general solution: because the roots are distinct and real,

x(t)=C1et+C2e3t.x(t)=C_1e^{-t}+C_2e^{-3t}.

The constants C1C_1 and C2C_2 would be fixed by two initial conditions, such as x(0)x(0) and x˙(0)\dot x(0).

Physical interpretation: both exponential terms decay as time increases. Neither term contains a sine or cosine, so no oscillation occurs. The damping is strong enough to prevent the mass from swinging repeatedly through equilibrium; instead, the displacement relaxes back toward

limtx(t)=0.\lim_{t\to\infty}x(t)=0.

This is an overdamped oscillator. Its two decay rates describe a rapidly disappearing transient e3te^{-3t} and a more slowly decaying tail ete^{-t}. After enough time, the slower term dominates unless its coefficient happens to be zero.

Where this leads

The move that solved the constant-coefficient equation was to choose functions that reproduce themselves under differentiation. The guess erte^{rt} turned a differential equation into an algebraic equation because derivatives act on exponentials only by multiplying them by powers of rr.

That idea extends far beyond the equations on this page. Fourier analysis, the next topic in this track, decomposes complicated functions into sums of the same exponential and oscillatory building blocks found here. Later, partial differential equations such as the wave equation and the Schrödinger equation in three dimensions can be attacked by separation of variables, which breaks one equation involving several variables into ordinary differential equations of exactly this kind.