Learning Objectives
By the end of this section you will be able to:
- Recognize a nonhomogeneous second-order linear ODE and explain why its solution splits as .
- Choose the correct trial form for when the forcing is a polynomial, exponential, sinusoid, or product/sum of these.
- Apply the "multiply by " rule when the trial form overlaps the homogeneous solution (the resonance case).
- Determine the unknown coefficients by substituting the trial back into the ODE and matching like terms.
- Apply initial conditions correctly to the total , not to alone.
- Implement the method in Python and verify it with PyTorch autograd.
The Big Picture: Forcing a System
"Section 22.01 showed how a system moves when nothing pushes it. This section asks: what happens when something does?"
Until now every ODE we have written had a zero on the right-hand side. Physically that meant a system left alone: a swinging pendulum after you let go, a charged capacitor discharging through a resistor, a spring released from its stretched position. The motion was governed entirely by the system's own internal dynamics — the homogeneous equation.
But the most useful problems involve external input: a constant gravitational pull, a sinusoidal voltage source, an oscillating piston, a sudden hammer-strike. Those become a nonhomogeneous ODE:
The function on the right-hand side is the forcing term — the input that drives the system. Solving this ODE answers a single, very practical question:
Given an external push , what motion does the system produce?
The Core Idea (in one line)
For a linear ODE, the answer always has the form
is what the system would do if nothing pushed it (the homogeneous solution from Section 22.01–03). is one specific motion that the ODE produces in response to the forcing. Adding the two gives every possible solution.
The Superposition Principle
Why can we split the solution into two pieces? Because the operator is linear. Linearity says: for any constants and any twice-differentiable ,
Now suppose is any single solution of , and let be the general solution of the homogeneous equation . Then:
So is also a solution. Conversely, if is any solution then satisfies , meaning is a homogeneous solution — call it . So . Every solution decomposes this way.
The strategy
To solve we only need:
- The general homogeneous solution (sections 22.01–22.03).
- One particular solution — any single function that satisfies the full equation.
- Add them and fit to the initial conditions on the TOTAL .
Finding is what this section is about.
The Method of Undetermined Coefficients
For certain special forcings — polynomials, exponentials, sines, cosines, and their sums and products — there is a remarkably clean recipe:
- Guess a trial form for with the same algebraic "family" as , but with unknown coefficients.
- Substitute the trial into the ODE.
- Match coefficients of like terms on both sides.
- Solve the resulting linear system for the unknowns.
Why does this work? Because differentiation maps these families to themselves. The derivative of a polynomial is a polynomial. The derivative of is — still an exponential of the same rate. The derivative of a sinusoid of frequency is a sinusoid of frequency . So the LHS of the ODE stays inside the family of the RHS, and the matching procedure terminates after finitely many algebraic steps.
What "undetermined" means
The coefficients () in the trial form are unknown until step 3 forces them. They are "determined" only AFTER you substitute and match — hence the name. There is no calculus magic; it is bookkeeping.
Catalog of Trial Forms
Memorize this table. It is the whole method, on one page.
| Forcing g(t) | Trial form y_p | Why |
|---|---|---|
| k (constant) | A | Derivatives of a constant are 0, so plug A into ODE: cA = k. |
| p₀ + p₁ t (linear) | A + B t | Same degree as the forcing. Polynomial in, polynomial out. |
| Polynomial of degree n | A₀ + A₁t + … + Aₙ tⁿ | Differentiation lowers degree; the highest-degree term of y_p must match the forcing. |
| K e^(αt) | A e^(αt) | e^(αt) is an eigenfunction of d/dt — multiplying by a constant is the only operation needed. |
| K cos(ωt) or K sin(ωt) | A cos(ωt) + B sin(ωt) | You need BOTH; differentiating cos produces sin, only the pair is closed under d/dt. |
| K e^(αt) cos(ωt) | e^(αt) (A cos(ωt) + B sin(ωt)) | Product of an exponential and a sinusoid — combine both rules. |
| Sum of the above | Corresponding sum of trial forms | Linearity: solve for each piece, then add. |
The matching principle
Always write the trial form so it contains every term you could get by differentiating it twice. That is why the sinusoid trial has both and : even if the forcing is just , the LHS of the ODE will produce sine terms.
The Resonance Rule: Multiply by
The catalog above breaks down in one important case: when the trial form is already a solution of the homogeneous equation.
Consider . The homogeneous roots are , so . Try :
The LHS collapses to zero no matter what we choose — because is already in the kernel of . Algebraically: , so the formula divides by zero.
The Resonance Rule
If the trial form overlaps the homogeneous solution , multiply the trial by . If it still overlaps (when the root is repeated), multiply by .
In symbols: the "multiplicity bump" equals the algebraic multiplicity of the root that causes the clash.
| Situation | Bumped trial form |
|---|---|
| α is NOT a root of the characteristic equation | A e^(αt) |
| α is a SIMPLE root | A t · e^(αt) |
| α is a DOUBLE root | A t² · e^(αt) |
| Forcing K cos(ωt), iω is NOT a homogeneous root | A cos(ωt) + B sin(ωt) |
| Forcing K cos(ωt), iω IS a homogeneous root (undamped at natural freq) | t · (A cos(ωt) + B sin(ωt)) |
Where the t comes from
This is exactly the same phenomenon you saw in Section 22.03 with : when a root coalesces, the second linearly independent solution always gains a factor of . Resonance is the SAME algebra — a root of the characteristic equation has "moved into" the forcing, so the same fix applies.
Physically, resonance is the most striking phenomenon in linear systems: a sinusoidal force at the system's natural frequency builds the amplitude without bound. This is why opera singers shatter wineglasses, why platoons break step on bridges, and why every engineer designs damping into rotating machinery.
Worked Example (Step-by-Step)
Solve subject to .
Click to expand the full hand calculation
Char. eq: . Factor: so . Hence
Forcing is , an exponential with rate . Is a root of the characteristic equation? . No clash — use the standard trial form.
Combine: .
. So .
At : .
so .
From the first equation, . Substitute: . Then .
At : ✓. ✓.
At : . The Python solver below returns , matching to 3 decimals.
The particular piece alone is , but the TOTAL — much smaller. The homogeneous piece is doing real work, fighting the forcing in the early transient so the IC's are honoured. Many students confuse with the actual physical motion — it is not, by itself.
Interactive Forcing Explorer
Pick a forcing type — polynomial, exponential, or sinusoid — and watch four curves update simultaneously: the forcing itself (dashed gray), the transient (green), the particular solution (blue), and the total (red). Try every preset.
Three things to discover
- Switch to exponential forcing and slide through the homogeneous roots (with the default they are and ). At those exact points an amber warning appears: the trial gets multiplied by .
- Switch to sinusoid, set , and sweep . The natural frequency is . Park exactly at 2 — the response grows like , the textbook resonance.
- Add even tiny damping and re-do the sweep. The unbounded growth disappears; the steady amplitude becomes large but finite. This is exactly why suspension bridges have dampers.
Transient vs Steady State
When the homogeneous solution decays — , the stable case — the picture splits naturally into two regimes.
| Regime | Dominated by | Time scale |
|---|---|---|
| Transient | y_h (initial conditions, free response) | Decays on the time-scale 1 / |Re(r)|. |
| Steady state | y_p (the forcing response) | Lasts forever — same shape as g(t). |
After the transient dies, . Engineers call this the steady-state response and spend enormous effort designing it: amplifier frequency response, loudspeaker damping, automotive suspension. The transient is the "ringing" before the system settles.
Why the initial conditions usually do not matter long-term
Notice that the IC's only show up in (they pin ). If , the IC information washes out. A stable, forced linear system forgets its starting conditions. This is the rigorous reason a hi-fi system doesn't depend on how you switched it on.
Computation in Python
We turn the recipe into code. Given and a description of , the function below returns the total , the transient , and the steady-state piece on any time grid. It dispatches on the forcing type, builds the trial-form coefficients in closed form, applies the resonance bump where needed, then solves a 2×2 system for the homogeneous constants from the total-y initial conditions.
Analytic solver for three families of forcings
The resonance amplitude curve
For sinusoidal forcing the steady-state amplitude as a function of is one of the most studied curves in engineering — every audio EQ, every seismometer's response, every NMR linewidth comes from it. Plot it once and remember the shape.
PyTorch View: Autograd Verification
Hand-derived ODE solutions are easy to get wrong. The cheapest test we know: feed the candidate back into the ODE and check the residual is machine-zero. PyTorch's autograd lets us compute and automatically — no chain-rule by hand, no finite differences.
Connection to physics-informed neural networks (PINNs)
Exactly this residual is what PINNs minimize: they parametrise as a neural network and train to make small at sampled collocation points. The method of undetermined coefficients gives the network the "target" — for the special class of linear ODEs with structured forcings, we already know the closed form, so PINNs should be able to recover it. This section's formulas are the analytic baseline against which every learned solver is measured.
Common Pitfalls
Applying the IC's to y_h instead of y
The initial conditions and apply to the total , not to alone. The correct IC's for are and . Forgetting to subtract is the single most common error in this section.
Forgetting the resonance bump
Always check whether your trial form is already in the homogeneous solution. If you skip this check and divide by the characteristic polynomial at , you will divide by zero (or worse, get a finite but completely wrong answer when round-off masks the zero).
Cos-only trial for cos-only forcing
Even if contains no sine, the trial form MUST include both: . Differentiation will produce sine terms whether you like it or not. A pure-cosine trial leads to an over-determined system with no solution.
Trying undetermined coefficients on g(t) = 1/t or g(t) = tan t
The method only works for the families listed in the catalog: polynomial × exponential × sinusoid. For , etc., the space of derivatives never closes — there is no finite trial form. For those forcings, use Variation of Parameters (Section 22.05).
Mistaking y_p for the physical motion
is ONE solution, often without the right initial values. The actual motion is with fitted to the IC's. The worked example shows this dramatically: but the actual .
Summary
Solving by undetermined coefficients is a four-step recipe:
- Solve the homogeneous equation. Get and the characteristic roots .
- Choose a trial form for matching the family of . If the trial overlaps , multiply by (or if the root is repeated).
- Substitute the trial into the ODE and match coefficients of like terms. Solve for the unknown constants.
- Write and apply the initial conditions to the TOTAL to pin .
Trial-form cheat sheet
| Forcing g(t) | Standard trial | Bump if resonant |
|---|---|---|
| Polynomial deg n | A₀ + A₁t + … + Aₙtⁿ | Multiply by t (or t²) if r=0 is a root |
| K e^(αt) | A e^(αt) | Multiply by t (or t²) if α is a root |
| K cos(ωt) or K sin(ωt) | A cos(ωt) + B sin(ωt) | Multiply by t if ±iω is a root |
| e^(αt)·polynomial | e^(αt) · (A₀ + … + Aₙtⁿ) | Multiply by t^k where k = multiplicity of α |
Coming next: Section 22.05 introduces Variation of Parameters — a method that handles any continuous forcing , including , , and arbitrary tabulated data. The price you pay is two integrals. Undetermined coefficients is faster when it applies; variation of parameters always applies.