Why this matters for simulation: Green's functions — responses to point sources — are how vortex methods and boundary element methods build flows.
By the end of this lesson you can…
Derive $y_p = u_1y_1 + u_2y_2$, explain why the extra condition $u_1'y_1 + u_2'y_2 = 0$ can always be imposed, and solve for $u_1', u_2'$ by Cramer's rule.
Solve $y'' + y = \sec t$ and $y'' - 4y' + 4y = e^{2t}\ln t$, which no finite guess can match, and check the answers against RK45.
Put an equation in standard form before applying the formulas, and compare the method with undetermined coefficients where both apply.
Write $y_p(t) = \int_{t_0}^t G(t,s)\,g(s)\,ds$ and prove that $G(\cdot,s)$ is the response to a unit kick at time $s$.
Approximate a forcing by $N$ kicks, measure the error against a reference, and explain which part of the error is first order in the kick width.
Say when the method stops: homogeneous solutions unknown, integrals not elementary, or a nonlinear equation.
Undetermined coefficients worked because the forcing belonged to a family that differentiation never leaves, and it failed for tant and 1/t. A gust on a wing is not in that family either: it switches on, swells and dies away, and a flight simulator must accept whatever shape the weather model supplies. This lesson’s method asks only that you can integrate g against two known functions. It builds on 5.1 Second-Order Linear Equations: Structure and 5.2 Constant Coefficients & the Characteristic Equation, and it ends in a picture worth keeping: the response to any forcing is a pile of tiny kicks, each ringing down on its own.
▶ VideoLetting the constants move, the 2x2 system and Cramer's rule, sec t and ln t, and the response as a sum of kicks that ring downcaptions only
Transcript
Undetermined coefficients needs a forcing whose derivatives stay in a small family. Secant t does not: each derivative is a new function, so no finite guess closes. This lesson's method only needs you to integrate.
Let the constants move: y p is u one times y one plus u two times y two. With two unknowns and one equation, choose u one prime y one plus u two prime y two to be zero. Then L of y one and y two vanish, leaving u one prime y one prime plus u two prime y two prime equals g.
That is a two by two system. Its matrix has determinant W, the Wronskian, never zero, so the condition was free. Cramer's rule gives u one prime equals minus y two g over W, and u two prime equals y one g over W. In the phase plane, u prime are the push's coordinates along the moving basis.
For y double prime plus y equals secant t, W is one, so u one prime is minus tangent and u two prime is one. Integrating, y p is cosine t log cosine t plus t sine t. At t equal one, formula and RK45 agree, about point five one. The slope grows without bound at pi over two.
A logarithm: y double prime minus four y prime plus four y equals e to the two t log t. The roots repeat, so W is e to the four t. By parts, y p is t squared e to the two t over four, times two log t minus three. RK45 agrees at t equal two and three.
When both methods apply, they agree. For y double prime plus six y prime plus eight y equals twelve e to the minus three t, variation of parameters needs a Wronskian and two integrals; the guess needs one line. Both give minus twelve e to the minus three t.
Integrate from a base time and y p is an integral of G of t, s times g of s. For fixed s, G solves the homogeneous equation; G of s, s is zero and its slope is one. A short push raises the velocity and barely moves y: G is the response to a unit kick.
Cut a forcing into N kicks. Here a steady push on a damped spring, twelve kicks. Each kick rings down as its own copy of G, scaled by its size. Their sum, in green, only roughly follows the dashed reference solve.
Double the kicks and the error drops. The largest error is about point two at twelve kicks and about point zero nine at twenty-four: a ratio of about two point two. Half the width, about half the error: first order.
Always first order? Up to ten twenty-four left kicks, the steady push gives ratios near two, but the gust gives ratios near four. The difference is g of zero: the leftover error is about half the width, times G, times g of zero, from the first kick alone.
Numerically, the method turns an ODE solve into integrals. For y double prime plus y equals one over one plus t squared, y of three is about point eight. Quadrature used one hundred five evaluations of g; RK45 used one thousand and ten, or two seventy-two at loose tolerance.
Where it stops: you need y one and y two in closed form; the integrals may not be elementary; the solution may not exist where you want it; the method is linear; and the kick picture holds only for pulses short against the system's timescale.
To recap: move the constants, impose one condition, and Cramer's rule gives u prime. Integrated from a base time, the answer is a sum of kicks, each ringing down as G. Divide to standard form first. Next: forced oscillations and resonance.
Let the constants move
Work in standard form L[y]=y′′+p(t)y′+q(t)y=g(t), with y1,y2 a fundamental set of L[y]=0 (so W=y1y2′−y1′y2=0). The homogeneous solutions are c1y1+c2y2 with constants c1,c2. Variation of parameters, due to Lagrange (from memory), keeps that shape and lets the constants move:
yp=u1(t)y1+u2(t)y2.
This is not a restriction. We now have two unknown functions but only one equation L[yp]=g to satisfy, so there is room for one more condition of our choosing. Differentiate:
yp′=u1′y1+u2′y2+u1y1′+u2y2′.
A second derivative of this would contain u1′′ and u2′′ and produce a harder problem than we started with. So choose the extra condition
u1′y1+u2′y2=0.
Then yp′=u1y1′+u2y2′ looks exactly as in the homogeneous case, and yp′′=u1′y1′+u2′y2′+u1y1′′+u2y2′′. Substituting into L and collecting the u1 and u2 terms,
because L[y1]=L[y2]=0. So the equation L[yp]=g and the chosen condition form a linear system for the two unknowns u1′,u2′:
(y1y1′y2y2′)(u1′u2′)=(0g).
Why the condition is free. The matrix is the Wronskian matrix, with determinant W=0, so the system has exactly one solution at every t. We are not forcing an impossible demand on u1,u2; we are choosing, out of the many pairs that produce a solution, the one that makes the algebra close.
Phase-plane picture. In the (y,y′) plane of 4.7 Energy & Symplectic Integrators the columns v1=(y1,y1′) and v2=(y2,y2′) are a moving basis. The homogeneous state is c1v1+c2v2 with constant coordinates; under forcing the coordinates drift with velocity (u1′,u2′), the coordinates of the push (0,g) in that basis. The push is a pure velocity kick, because forcing enters the second component only.
Cramer’s rule. Eliminating from ax+bz=e, cx+dz=f gives x=(ed−bf)/(ad−bc) and z=(af−ec)/(ad−bc): each unknown is a ratio of determinants, with the right-hand side swapped into the unknown’s column. Geometrically (1.4 Determinants as Volume Scaling) the denominator is the signed area of the parallelogram of the columns and the numerator is that area after the swap. Here the denominator is W, and the numerators are 0⋅y2′−y2g and y1g−y1′⋅0:
u1′=−Wy2g,u2′=Wy1g
Integrate both, and yp=u1y1+u2y2. Block A of the lab has sympy solve the system for general y1,y2,g and confirm both formulas (differences 0). The integration constants only add c1y1+c2y2, so any choice gives a valid yp.
Standard form is not optional. The formulas assume y′′ has coefficient 1. For a(t)y′′+b(t)y′+c(t)y=f(t) use g=f/a; forgetting to divide is the commonest error here, and the answer fails the equation.
1. A forcing no guess can match.y′′+y=sect on −π/2<t<π/2. The derivatives of sect are secttant, then secttan2t+sec3t, and so on: each is a new function, so no finite guess closes. Take y1=cost, y2=sint, so W=cos2t+sin2t=1:
u1′=−sintsect=−tant,u2′=costsect=1.
Integrating, u1=lncost (since (lncost)′=−tant) and u2=t, so
yp=costlncost+tsint.
These are the integrals from t0=0, so yp(0)=0 and yp′(0)=0. Block B confirms a residual of 0 and prints yp(1)=0.508847, yp′(1)=1.058334, yp(1.5)=1.308875; RK45 on the ODE gives 0.508847 and 1.308875. Near the end of the interval yp′=−sintlncost+tcost grows without bound as cost→0, because the forcing does: the block prints yp′(1.5)=2.748254 and yp′(1.55)=3.904445. The solution cannot be continued past π/2 because sect is not defined there.
By parts, ∫tlntdt=2t2lnt−4t2 and ∫lntdt=tlnt−t. So u1=−2t2lnt+4t2, u2=tlnt−t, and
yp=e2t[−2t2lnt+4t2+t2lnt−t2]=4t2e2t(2lnt−3).
Block B checks the residual (0) and RK45 started from the data of yp at t=1 (−5.541792 and −18.472640): at t=2 both give −88.105343, at t=3 both give −728.6911.
A second route checks the mechanism. With s=2 a double root, the shift identity of the last lesson collapses to L[ue2t]=e2tu′′, so y=ve2t with v′′=lnt, and two integrations give v=2t2lnt−43t2 (block B confirms yp/e2t−v=0). Variation of parameters found that double integral without noticing the shift; a finite guess fails because it cannot know it needs lnt.
3. Both methods apply.y′′+6y′+8y=12e−3t. The roots are −2 and −4, so y1=e−2t, y2=e−4t and W=e−2t(−4e−4t)−(−2e−2t)e−4t=−2e−6t.
Variation of parameters.u1′=−−2e−6te−4t⋅12e−3t=6e−t, so u1=−6e−t; u2′=−2e−6te−2t⋅12e−3t=−6et, so u2=−6et. Then yp=−6e−te−2t−6ete−4t=−12e−3t.
Undetermined coefficients.−3 is not a root, P(−3)=9−18+8=−1, and yp=12/(−1)e−3t=−12e−3t.
They agree exactly here because the antiderivatives with no constant added happen to give −12e−3t. Other constants would add c1e−2t+c2e−4t, never anything outside that family. Undetermined coefficients took one line and no integral; variation of parameters took a Wronskian and two integrals. Use the guess when the forcing is in the table and the integral formula when it is not. Block C prints W, u1, u2 and the sum from sympy.
From the formula to a kick
Integrate from a base time t0 instead of using indefinite integrals: u1(t)=−∫t0ty2g/Wds and u2(t)=∫t0ty1g/Wds. The factors y1(t) and y2(t) do not depend on s, so they go inside the integrals:
Two facts about G follow directly. For fixed s, as a function of t it is a combination of y1(t) and y2(t), so G(⋅,s) solves the homogeneous equation. And
Block A has sympy confirm both for arbitrary y1,y2.
Why this is a kick. Suppose a short push g acts on [s,s+Δ]. Integrating y′′=g−py′−qy over that short interval, the right side’s second and third terms are bounded, so y′ gains about g(s)Δ while the push changes y itself only by an amount of order Δ2 (the extra distance covered while the extra velocity builds up). The push is a jump in velocity of size g(s)Δ, nothing else. After it the equation is homogeneous, with data (y,y′)=(0,g(s)Δ) at time s. By linearity that solution is g(s)Δ times the one with data (0,1), and the two properties above say that solution is G(t,s). So G(t,s) is the response at time t to a unit kick at time s, and the formula adds up all the kicks:
yp(t)≈k∑G(t,sk)g(sk)Δs,
which is a Riemann sum for the integral.
The integral solves the ODE. By Leibniz’s rule for a variable upper limit (from memory), dtd∫t0tF(t,s)ds=F(t,t)+∫t0t∂tFds, and G(t,t)=0, so
Since ∂t2G=−p∂tG−qG, we get yp′′+pyp′+qyp=g, with yp(t0)=yp′(t0)=0. This second proof does not use the system for u1′,u2′. The partial derivative ∂tG holds s fixed, as in 2.1 Functions of Several Variables & Partial Derivatives.
For distinct real roots, put y1=er1t, y2=er2t, W(s)=(r2−r1)e(r1+r2)s in G: the numerator is er1s+r2t−er1t+r2s and dividing gives (er2(t−s)−er1(t−s))/(r2−r1), the first row. For example 3, G(τ)=21(e−2τ−e−4τ), and the solution with y(0)=y′(0)=0 is
It is the guess’s −12e−3t plus the homogeneous part 6e−2t+6e−4t that cancels the starting values (initial conditions last). Block C prints y(1)=0.32446071 from the integral of Gg, from this closed form and from RK45, with residual 0 and start values 0,0.
A preview. For constant coefficients yp(t)=∫0tG(t−s)g(s)ds, a convolution (from memory, the name only). The ideal kick, an infinitely thin spike of unit area, is the Dirac delta (from memory), and G is the impulse response. The Laplace module (impulses and delta, convolution and transfer function) turns the convolution into a product.
Play with it
◆ InteractiveCut the forcing into N kicks: each rings down as G, the sum approaches the RK4 reference, and the error ratio when N doubles is printed
Loading simulation…
The default is y′′+0.6y′+4y=1 (a steady push switched on at t=0), y(0)=y′(0)=0, N=12 kicks of width 10/12. The top strip draws g and the kicks g(sk)Δs; the main plot draws each kick’s own ring-down G(t−sk)g(sk)Δs (for N≤30), their sum, and the RK4 reference, which the readout checks against itself at half the step (a gap of order 10−12). The readout gives the largest error over the time grid, the error with 2N kicks, and their ratio: at N=12, 1.996×10−1 against 9.207×10−2 at 2N=24, ratio 2.168. Press Double N: the table lists the error for N=2,4,…,1024 for both placements, and the log-log plot adds guide lines of slope −1 and −2 (guides only).
For the steady push the left-kick ratio from N/2 to N is 2.013, 2.008, 2.003 at N=256,512,1024: first order, the error halving when the width halves. For the 1-cosine gust it is 4.005, 4.003, 3.999: second order. The difference is not a jump in g (neither forcing has one) but the starting value, g(0)=1 against g(0)=0. Mechanism: on one piece [s,s+Δ] the integrand F(s)=G(t−s)g(s) has ∫F=F(s)Δ+21F′(s)Δ2+…, so the left-kick sum misses about 21F′Δ2 per piece, and over all pieces 21Δ∫F′ds=21Δ(F(t)−F(0)). Since F(t)=G(0)g(t)=0 and F(0)=G(t)g(0), the first-order error is about 21Δ∣G(t)∣∣g(0)∣: it comes from the first kick alone and vanishes when g(0)=0. Block E tests it: with maxG=0.403080, the estimate (T/2N)maxG is 1.5745×10−2 at N=128 and 1.9682×10−3 at N=1024, against measured left-kick errors 1.5963×10−2 and 1.9718×10−3.
Tick midpoint kicks: expanding F about the middle of a piece, odd terms cancel and the per-piece error is of order Δ3. The table ratios are between 3.748 and 4.390 at N=256,512,1024 for the push and between 3.743 and 4.353 for the gust, scattered around 4 because the maximum is taken over a finite grid. The square wave has jumps inside the kick pieces; its left-kick ratios range from 1.578 to 3.156, irregular, and I claim no order for it.
Quadrature against RK45, and what it costs
Numerically, variation of parameters turns an ODE solve into two integrals. For y′′+y=1/(1+t2) with y(0)=y′(0)=0 (y1=cos, y2=sin, W=1):
y(T)=sinT∫0T1+s2cossds−cosT∫0T1+s2sinsds.
Neither integral has an elementary antiderivative (from memory; they involve sine and cosine integrals of complex argument), so whichever route you take, the answer is a number from quadrature. Block D gives ∫03=0.624404 and 0.715113, so y(3)=0.7960722734; RK45 gives 0.7960722734 too, a gap of 2.52×10−12. scipy.integrate.quad used 105 evaluations of g; RK45 at tolerance 10−11 made 1010 calls, and at 10−8 it made 272 with an error of 2.64×10−9 in y(3).
For y at many times, use the separable form G(t,s)=(y1(s)y2(t)−y1(t)y2(s))/W(s): the integrands do not depend on t, so one pass of two cumulative trapezoid sums over 3001 points (3001 evaluations of g) gives y at all of them, with a gap to RK45 of 9.08×10−8 (the trapezoid rule’s second-order error, from memory, plus RK45’s). The price is that you need y1 and y2 in closed form, which RK45 does not.
Where the method stops
It needs y1 and y2 in closed form. For the Airy equation y′′−ty=0 (from memory) you do not have them. Computing them numerically means integrating the homogeneous system, and then integrating the forced equation once is simpler.
The integrals may not be elementary, as in the 1/(1+t2) example: the method is correct, but the answer is a number from quadrature.
The solution may not exist where you want it: the sect answer lives on (−π/2,π/2).
It is linear. For y′′+y2=g the response to two kicks is not the sum of the responses.
The kick picture is a model, good only for pulses short against the system’s timescale (problem 2).
Lab
Blocks: A Cramer and G for general y1,y2; B the sect and lnt examples; C the comparison with undetermined coefficients; D quadrature against RK45; E kick sums and the endpoint estimate; F the problems.
🐍 PythonLab: the 2x2 system with sympy, the kick function, quadrature against RK45, convergence of kick sums
⌘/Ctrl + Enter
Exercise: variation of parameters as two integrals, and as a sum of kicks
Implement the formulas of this lesson and compare with RK45: vop_rates (u1′,u2′), vop_particular (two cumulative trapezoid sums), kick_sum (left-end kicks, leaving out kicks that come after the time you evaluate) and rk45_gap.
🧪 Coding exerciseExercise: variation of parameters by quadrature and by kicks, checked against RK45✓ passed
⌘/Ctrl + Enter
💡 u1' = -y2 g / W and u2' = y1 g / W with W = y1 dy2 - dy1 y2. For kick_sum build a matrix of t - s_k with np.newaxis, apply G, zero the entries where t - s_k is not positive, multiply by the kick sizes g(s_k) T / N and sum over k.
Problems
✏️ Pen & paperA repeated root and a negative power●●○
Solve y′′−6y′+9y=e3t/t2 for t>0 with y(1)=e3, y′(1)=4e3. Check the particular solution with the shift identity.
Show worked solution
P(r)=(r−3)2, so y1=e3t, y2=te3t and W=e3t(1+3t)e3t−3e3t⋅te3t=e6t. With g=e3t/t2:
So u1=−lnt, u2=−1/t, and yp=−e3tlnt−e3t. The term −e3t is homogeneous, so yp=−e3tlnt also works. Shift check: with s=3 a double root, L[ve3t]=e3tv′′, so v′′=1/t2 and v=−lnt plus a line.
General solution y=−e3tlnt+(c1+c2t)e3t. Impose the data on the sum: y(1)=(c1+c2)e3=e3 gives c1+c2=1. With y′=e3t[3(−lnt+c1+c2t)−1/t+c2], y′(1)=e3[3−1+c2]=4e3 gives c2=2, c1=−1:
y=e3t(2t−1−lnt).
Block F confirms residual 0, the two data values and y(2)=e6(3−ln2)=930.6508.
✏️ Pen & paperWhen is a pulse a kick?●●○
A mass-spring y′′+25y=g(t) (natural frequency ω=5) starts at rest and receives g=10 for 0≤t≤0.4, then g=0. (a) Use G(τ)=sin(5τ)/5 to find y(t) for t>0.4 and its amplitude. (b) Compare with a single ideal kick of the same area at t=0. (c) How short must the pulse be for the amplitude to be within 1% of the kick’s?
Show worked solution
(a) For t>0.4: y=∫00.45sin5(t−s)10ds=2∫00.4sin5(t−s)ds=52[cos5(t−s)]s=00.4=52(cos5(t−0.4)−cos5t). Sum to product, cosA−cosB=−2sin2A+Bsin2A−B with A=5t−2, B=5t:
y=54sin(1)sin(5t−1).
The amplitude is 0.8sin1=0.673177. Check: y(2)=0.673177sin9=0.277429, and RK45 with the pulse switched off at 0.4 gives 0.277429 (block F).
(b) The area is 10×0.4=4, so a kick at t=0 gives y=54sin5t with amplitude 0.8. The pulse gives 0.8⋅sin(1)/1, i.e. 0.841471 of that, and the phase 5t−1=5(t−0.2) is that of a kick at the centre of the pulse, t=0.2.
(c) In general the amplitude ratio is sin(x)/x with x=ωD/2. It equals 0.99 at x=0.24532, so D=2x/ω=0.09813 s: under a tenth of a second, under a twelfth of the natural period 2π/5=1.2566 s.
Solve t2y′′+ty′−y=t2lnt for t>0. (a) Show that y1=t and y2=1/t solve the homogeneous equation and find W and check it with Abel’s theorem. (b) Find a particular solution. (c) Say what goes wrong if you use g=t2lnt.
Show worked solution
(a) y=t: 0+t−t=0. y=1/t: t2⋅2/t3+t(−1/t2)−1/t=2/t−1/t−1/t=0. W=t⋅(−1/t2)−1⋅(1/t)=−2/t. Standard form has p=1/t, and Abel gives W∝e−∫p=1/t, consistent with −2/t.
(b) Standard form: y′′+y′/t−y/t2=lnt, so g=lnt. Then
By parts: u1=21(tlnt−t) and u2=−21(3t3lnt−9t3). Then yp=tu1+u2/t=21t2lnt−21t2−61t2lnt+181t2=31t2lnt−94t2=9t2(3lnt−4). Block F checks the residual (0) and prints yp(2)=−0.853582, yp(4)=0.282459; RK45 from the data of yp at t=1 gives the same.
(c) g must be what sits on the right of the standard form. With g=t2lnt you would be solving y′′+y′/t−y/t2=t2lnt, which is t2y′′+ty′−y=t4lnt once multiplied back by t2: a different equation, so the yp you compute does not satisfy the original one.
✅ Concept check
Why can we impose $u_1'y_1 + u_2'y_2 = 0$ in the derivation of variation of parameters?
Why: The extra condition is a convenience that costs nothing, because the Wronskian matrix is invertible.
✅ Concept check
For $y'' - y = g(t)$ use $y_1 = e^t$, $y_2 = e^{-t}$ in $G(t,s) = (y_1(s)y_2(t) - y_1(t)y_2(s))/W(s)$. What is $G$ for $t - s = 1$? Give a decimal.
Why: $W(s) = e^s(-e^{-s}) - e^se^{-s} = -2$, and the numerator is $e^{s-t} - e^{t-s}$, so $G = \sinh(t - s)$, and $\sinh1 = 1.1752$.
✅ Concept check
To use $u_1' = -y_2g/W$ on $t^2y'' + ty' - y = 5t$, which $g$ should you use?
Why: The formulas are derived for $y'' + py' + qy = g$, with $1$ in front of $y''$.
Key Takeaways
Variation of parameters keeps yp=u1y1+u2y2 and lets the constants move; the condition u1′y1+u2′y2=0 is a free choice because the Wronskian matrix is invertible.
Cramer’s rule on the 2×2 system gives u1′=−y2g/W and u2′=y1g/W for y′′+py′+qy=g in standard form; divide by the leading coefficient first.
It solves what guessing cannot, such as sect (answer costlncost+tsint) and e2tlnt, and agrees with the guess where both apply; constants of integration only add homogeneous solutions.
yp=∫t0tG(t,s)g(s)ds, and G(⋅,s) solves the homogeneous equation with G(s,s)=0, ∂tG(s,s)=1: the response to a unit kick at time s. For constant coefficients G depends on t−s only.
A sum of N kicks converges to the response; left kicks are first order when g(0)=0 (measured ratio 2.003 at N=1024) and second order when g(0)=0 (3.999), and a pulse acts as a kick only if it is short against the system’s timescale.
Limits: closed-form y1,y2 are required, the integrals may need quadrature, and the equation must be linear.
Finished this lesson?
Mark it complete to track your progress (saved in this browser). Reading every section does this for you.