# This is a code cell that imports the necessary libraries for our session.import numpy as np # NumPy for numerical computationsimport sympy as sym # SymPy for symbolic mathematicsimport matplotlib as mpl # Matplotlib for plottingimport matplotlib.pyplot as plt # Matplotlib pyplot interfacefrom IPython.display import Math, displaympl.rcParams['figure.dpi'] =150mpl.rcParams['axes.spines.top'] =Falsempl.rcParams['axes.spines.right'] =False
In this document we work through fully solved examples for the topics covered in Sections 2.2 and 2.3 of the text:
§2.2 — Homogeneous second-order linear constant-coefficient ODEs. The three cases for the characteristic roots (real distinct, repeated, complex conjugate) are each illustrated.
§2.3 — Nonhomogeneous equations solved by the method of undetermined coefficients, with polynomial, exponential, and sinusoidal forcing functions, including the modification rule when a term in the trial solution duplicates a homogeneous solution.
Each example is worked “by hand” first and then verified using SymPy.
§2.2 Homogeneous Equations
A second-order linear constant-coefficient homogeneous ODE has the form \[
ay'' + by' + cy = 0, \qquad a \neq 0.
\] The solution strategy is to substitute the trial function \(y = e^{rt}\) and solve the characteristic equation\[
ar^2 + br + c = 0.
\] The nature of the two roots \(r_1, r_2\) determines the form of the general solution.
Example 1 — Real Distinct Roots
Find the general solution of \[y'' - y' - 6y = 0,\] and solve the initial value problem with \(y(0) = 1\), \(y'(0) = -1\).
Since \(r_1 \neq r_2\) are both real, two linearly independent solutions are \(e^{3t}\) and \(e^{-2t}\), so the general solution is \[
\boxed{y(t) = C_1 e^{3t} + C_2 e^{-2t}.}
\]
Solve the \(2 \times 2\) linear system. From the first equation \(C_1 = 1 - C_2\). Substitute into the second: \[
3(1 - C_2) - 2C_2 = -1
\;\Longrightarrow\;
3 - 5C_2 = -1
\;\Longrightarrow\;
C_2 = \frac{4}{5}.
\] Then \(C_1 = 1 - \dfrac{4}{5} = \dfrac{1}{5}\).
The particular solution is \[
\boxed{y(t) = \frac{1}{5}e^{3t} + \frac{4}{5}e^{-2t}.}
\]
Tip
Long-run behavior. As \(t \to \infty\) the term \(\tfrac{1}{5}e^{3t}\) dominates since \(3 > -2\), so \(y(t) \to +\infty\). If \(C_1 = 0\) (obtainable by choosing \(y(0) = 0\), \(y'(0) = 2\)), the solution decays to zero.
Figure 1: Solutions of \(y'' - y' - 6y = 0\) for several initial conditions. The particular solution satisfying \(y(0)=1\), \(y'(0)=-1\) is highlighted in red.
Example 2 — Repeated Root
Find the general solution of \[y'' + 6y' + 9y = 0,\] and solve the initial value problem with \(y(0) = 2\), \(y'(0) = -3\).
When the characteristic equation has a repeated root \(r_1 = r_2 = r\), the two linearly independent solutions are \(e^{rt}\) and \(t e^{rt}\). Here \(r = -3\), so \[
\boxed{y(t) = C_1 e^{-3t} + C_2\, t e^{-3t} = (C_1 + C_2 t)\,e^{-3t}.}
\]
Note
Why \(te^{rt}\)? If we only used \(e^{rt}\) twice we would not have two independent solutions. The factor of \(t\) is required to generate a second independent solution; this can be verified rigorously using the method of reduction of order.
Figure 2: Solutions of \(y'' + 6y' + 9y = 0\) (repeated root \(r=-3\)). All solutions decay to zero. The particular solution satisfying \(y(0)=2\), \(y'(0)=-3\) is highlighted in red.
Example 3 — Complex Conjugate Roots
Find the general solution of \[y'' - 4y' + 13y = 0,\] and solve the initial value problem with \(y(0) = 0\), \(y'(0) = 3\).
The particular solution is \[
\boxed{y(t) = e^{2t}\sin(3t).}
\]
Tip
Amplitude growth. Because \(\alpha = 2 > 0\), the exponential envelope \(e^{2t}\) grows without bound; the oscillations increase in amplitude. If \(\alpha < 0\) the envelope would decay (damped oscillations), and if \(\alpha = 0\) the oscillations would have constant amplitude (pure oscillation).
Figure 3: Solutions of \(y'' - 4y' + 13y = 0\) (complex roots \(r = 2\pm 3i\)). The growing exponential envelope \(\pm e^{2t}\) is shown dashed. The particular solution \(y = e^{2t}\sin(3t)\) is highlighted in red.
§2.3 Nonhomogeneous Equations — Method of Undetermined Coefficients
A nonhomogeneous second-order linear constant-coefficient ODE has the form \[
ay'' + by' + cy = f(t),
\] where \(f(t) \not\equiv 0\) is the forcing function. The general solution is \[
y(t) = y_h(t) + y_p(t),
\] where \(y_h\) is the general solution of the associated homogeneous equation and \(y_p\) is any particular solution of the full nonhomogeneous equation.
The method of undetermined coefficients finds \(y_p\) by guessing a trial function whose form mirrors that of \(f(t)\), substituting it into the ODE, and matching coefficients. The method applies when \(f(t)\) is a polynomial, an exponential, a sine or cosine, or a product of these.
Example 4 — Polynomial Forcing
Solve the initial value problem \[y'' + 4y' + 4y = 3t^2 - 2, \qquad y(0) = 1,\quad y'(0) = 0.\]
Since \(f(t) = 3t^2 - 2\) is a degree-2 polynomial and neither \(t^0\) nor \(t^1\) nor \(t^2\) appears in \(y_h\), we try a full degree-2 polynomial: \[
y_p = At^2 + Bt + D.
\] (We use \(D\) instead of \(C\) to avoid confusion with the constants \(C_1\), \(C_2\).)
Step 3 — Compute the required derivatives and substitute.
The forcing function is \(f(t) = 6e^{2t}\). Since \(e^{2t}\) does not appear in \(y_h\) (the exponents \(5\) and \(-2\) differ from \(2\)), we try \[
y_p = Ae^{2t}.
\]
Step 3 — Substitute and solve for \(A\).
\[
y_p' = 2Ae^{2t}, \qquad y_p'' = 4Ae^{2t}.
\]
Substituting into the ODE: \[
4Ae^{2t} - 3(2Ae^{2t}) - 10(Ae^{2t}) = 6e^{2t}
\]\[
(4 - 6 - 10)Ae^{2t} = 6e^{2t}
\]\[
-12A = 6 \;\Longrightarrow\; A = -\frac{1}{2}.
\]
Example 6 — Exponential Forcing (Modification Rule)
Find the general solution of \[y'' - 3y' - 10y = 6e^{-2t}.\]
By Hand
Step 1 — Homogeneous solution.
From Example 5 the characteristic roots are \(r_1 = 5\) and \(r_2 = -2\), giving \[
y_h = C_1 e^{5t} + C_2 e^{-2t}.
\]
Step 2 — Identify the conflict.
The forcing function \(f(t) = 6e^{-2t}\) has the same exponent \(-2\) as the homogeneous solution \(e^{-2t}\). If we naively tried \(y_p = Ae^{-2t}\), substitution would give \(0 = 6e^{-2t}\) (a contradiction) because \(Ae^{-2t}\) already satisfies the homogeneous equation.
Modification rule: multiply the trial function by \(t\): \[
y_p = Ate^{-2t}.
\]
Modification rule summary. If the natural trial function for \(y_p\) duplicates a term already present in \(y_h\), multiply the trial by \(t\). If it duplicates a term in \(y_h\) that itself arose from a repeated characteristic root, multiply by \(t^2\).
The forcing function \(f(t) = 5\cos(2t)\) has frequency \(2\), while the homogeneous solutions oscillate at frequency \(3\). Since \(\cos(2t)\) and \(\sin(2t)\) do not appear in \(y_h\) (because \(2 \neq 3\)), we try \[
y_p = A\cos(2t) + B\sin(2t).
\]
The particular solution is remarkably clean: \[
\boxed{y(t) = \cos(2t).}
\]
Tip
This IVP happens to be satisfied by the particular solution alone. In general the homogeneous terms will be nonzero after applying the initial conditions.
Figure 4: Solution of \(y'' + 9y = 5\cos(2t)\) with \(y(0)=1\), \(y'(0)=0\). The particular (forced) response \(\cos(2t)\) and the homogeneous (natural) response are both shown. Here \(C_1 = C_2 = 0\) so the full solution equals the forced response alone.
Example 8 — Sinusoidal Forcing at the Natural Frequency (Resonance)
Find the general solution of \[y'' + 9y = 5\cos(3t).\]
By Hand
Step 1 — Homogeneous solution.
From Example 7, \(y_h = C_1\cos(3t) + C_2\sin(3t)\).
Step 2 — Identify the conflict.
The forcing function \(f(t) = 5\cos(3t)\) oscillates at frequency \(3\), which matches the natural frequency of the system. The trial \(y_p = A\cos(3t) + B\sin(3t)\) would duplicate terms already in \(y_h\).
Resonance. The particular solution \(y_p = \dfrac{5}{6}\,t\sin(3t)\) grows in amplitude without bound as \(t \to \infty\) because the forcing frequency exactly matches the system’s natural frequency \(\omega_0 = 3\). This phenomenon is called pure resonance. In physical systems (springs, circuits) even small sustained forces at the natural frequency can produce unbounded oscillations.
Figure 5: General solution of \(y'' + 9y = 5\cos(3t)\) with \(C_1 = C_2 = 0\), showing the resonant response \(y_p = \tfrac{5}{6}t\sin(3t)\). The amplitude grows linearly with time.
TipExpand for Session Info
import sysprint("Python version:", sys.version)print('\n'.join(f'{m.__name__}=={m.__version__}'for m inglobals().values()ifgetattr(m, '__version__', None)))