Flow Lab

Syllabus / Module 5: Second-Order Linear ODEs & Oscillations

Lesson 5.5

Variation of Parameters

A general method for any forcing term using the Wronskian; Green's functions preview.

Written byClaude Sonnet

🌊
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.
On this page
·
  1. Let the constants move
  2. Worked examples
  3. From the formula to a kick
  4. Play with it
  5. Quadrature against RK45, and what it costs
  6. Where the method stops
  7. Lab
  8. Exercise: variation of parameters as two integrals, and as a sum of kicks
  9. Problems
  10. Key Takeaways

Undetermined coefficients worked because the forcing belonged to a family that differentiation never leaves, and it failed for tan⁡t\tan t and 1/t1/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 gg 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.

▶ Video Letting 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
  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. 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.
  10. 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.
  11. 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.
  12. 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.
  13. 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)L[y] = y'' + p(t)y' + q(t)y = g(t), with y1,y2y_1, y_2 a fundamental set of L[y]=0L[y] = 0 (so W=y1y2′−y1′y2≠0W = y_1y_2' - y_1'y_2 \neq 0). The homogeneous solutions are c1y1+c2y2c_1y_1 + c_2y_2 with constants c1,c2c_1, c_2. Variation of parameters, due to Lagrange (from memory), keeps that shape and lets the constants move:

yp=u1(t) y1+u2(t) y2.y_p = u_1(t)\,y_1 + u_2(t)\,y_2 .

This is not a restriction. We now have two unknown functions but only one equation L[yp]=gL[y_p] = g to satisfy, so there is room for one more condition of our choosing. Differentiate:

yp′=u1′y1+u2′y2+u1y1′+u2y2′.y_p' = u_1'y_1 + u_2'y_2 + u_1y_1' + u_2y_2' .

A second derivative of this would contain u1′′u_1'' and u2′′u_2'' and produce a harder problem than we started with. So choose the extra condition

u1′y1+u2′y2=0.u_1'y_1 + u_2'y_2 = 0 .

Then yp′=u1y1′+u2y2′y_p' = u_1y_1' + u_2y_2' looks exactly as in the homogeneous case, and yp′′=u1′y1′+u2′y2′+u1y1′′+u2y2′′y_p'' = u_1'y_1' + u_2'y_2' + u_1y_1'' + u_2y_2''. Substituting into LL and collecting the u1u_1 and u2u_2 terms,

L[yp]=u1L[y1]+u2L[y2]+u1′y1′+u2′y2′=u1′y1′+u2′y2′,L[y_p] = u_1L[y_1] + u_2L[y_2] + u_1'y_1' + u_2'y_2' = u_1'y_1' + u_2'y_2' ,

because L[y1]=L[y2]=0L[y_1] = L[y_2] = 0. So the equation L[yp]=gL[y_p] = g and the chosen condition form a linear system for the two unknowns u1′,u2′u_1', u_2':

(y1y2y1′y2′)(u1′u2′)=(0g).\begin{pmatrix} y_1 & y_2 \\ y_1' & y_2' \end{pmatrix}\begin{pmatrix} u_1' \\ u_2' \end{pmatrix} = \begin{pmatrix} 0 \\ g \end{pmatrix} .

Why the condition is free. The matrix is the Wronskian matrix, with determinant W≠0W \neq 0, so the system has exactly one solution at every tt. We are not forcing an impossible demand on u1,u2u_1, u_2; 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′)(y, y') plane of 4.7 Energy & Symplectic Integrators the columns v⃗1=(y1,y1′)\vec v_1 = (y_1, y_1') and v⃗2=(y2,y2′)\vec v_2 = (y_2, y_2') are a moving basis. The homogeneous state is c1v⃗1+c2v⃗2c_1\vec v_1 + c_2\vec v_2 with constant coordinates; under forcing the coordinates drift with velocity (u1′,u2′)(u_1', u_2'), the coordinates of the push (0,g)(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=eax + bz = e, cx+dz=fcx + dz = f gives x=(ed−bf)/(ad−bc)x = (ed - bf)/(ad - bc) and z=(af−ec)/(ad−bc)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 WW, and the numerators are 0⋅y2′−y2g0\cdot y_2' - y_2g and y1g−y1′⋅0y_1g - y_1'\cdot0:

 u1′=−y2 gW,u2′=y1 gW \boxed{\,u_1' = -\frac{y_2\,g}{W}, \qquad u_2' = \frac{y_1\,g}{W}\,}

Integrate both, and yp=u1y1+u2y2y_p = u_1y_1 + u_2y_2. Block A of the lab has sympy solve the system for general y1,y2,gy_1, y_2, g and confirm both formulas (differences 00). The integration constants only add c1y1+c2y2c_1y_1 + c_2y_2, so any choice gives a valid ypy_p.

Standard form is not optional. The formulas assume y′′y'' has coefficient 11. For a(t)y′′+b(t)y′+c(t)y=f(t)a(t)y'' + b(t)y' + c(t)y = f(t) use g=f/ag = f/a; forgetting to divide is the commonest error here, and the answer fails the equation.

First order, for comparison. For y′+py=gy' + py = g with y1=e−∫py_1 = e^{-\int p}, put y=uy1y = uy_1: then u′y1=gu'y_1 = g, the integrating factor of 3.4 Linear First-Order Equations & Integrating Factors in disguise.

Worked examples

1. A forcing no guess can match. y′′+y=sec⁡ty'' + y = \sec t on −π/2<t<π/2-\pi/2 \lt t \lt \pi/2. The derivatives of sec⁡t\sec t are sec⁡ttan⁡t\sec t\tan t, then sec⁡ttan⁡2t+sec⁡3t\sec t\tan^2t + \sec^3t, and so on: each is a new function, so no finite guess closes. Take y1=cos⁡ty_1 = \cos t, y2=sin⁡ty_2 = \sin t, so W=cos⁡2t+sin⁡2t=1W = \cos^2t + \sin^2t = 1:

u1′=−sin⁡t sec⁡t=−tan⁡t,u2′=cos⁡t sec⁡t=1.u_1' = -\sin t\,\sec t = -\tan t, \qquad u_2' = \cos t\,\sec t = 1 .

Integrating, u1=ln⁡cos⁡tu_1 = \ln\cos t (since (ln⁡cos⁡t)′=−tan⁡t(\ln\cos t)' = -\tan t) and u2=tu_2 = t, so

yp=cos⁡t ln⁡cos⁡t+tsin⁡t.y_p = \cos t\,\ln\cos t + t\sin t .

These are the integrals from t0=0t_0 = 0, so yp(0)=0y_p(0) = 0 and yp′(0)=0y_p'(0) = 0. Block B confirms a residual of 00 and prints yp(1)=0.508847y_p(1) = 0.508847, yp′(1)=1.058334y_p'(1) = 1.058334, yp(1.5)=1.308875y_p(1.5) = 1.308875; RK45 on the ODE gives 0.5088470.508847 and 1.3088751.308875. Near the end of the interval yp′=−sin⁡tln⁡cos⁡t+tcos⁡ty_p' = -\sin t\ln\cos t + t\cos t grows without bound as cos⁡t→0\cos t \to 0, because the forcing does: the block prints yp′(1.5)=2.748254y_p'(1.5) = 2.748254 and yp′(1.55)=3.904445y_p'(1.55) = 3.904445. The solution cannot be continued past π/2\pi/2 because sec⁡t\sec t is not defined there.

2. A logarithm. y′′−4y′+4y=e2tln⁡ty'' - 4y' + 4y = e^{2t}\ln t for t>0t \gt 0. Here P(r)=(r−2)2P(r) = (r - 2)^2, so y1=e2ty_1 = e^{2t} and y2=te2ty_2 = te^{2t} (5.2 Constant Coefficients & the Characteristic Equation), with W=e4tW = e^{4t}:

u1′=−te2t⋅e2tln⁡te4t=−tln⁡t,u2′=e2t⋅e2tln⁡te4t=ln⁡t.u_1' = -\frac{te^{2t}\cdot e^{2t}\ln t}{e^{4t}} = -t\ln t, \qquad u_2' = \frac{e^{2t}\cdot e^{2t}\ln t}{e^{4t}} = \ln t .

By parts, ∫tln⁡t dt=t22ln⁡t−t24\int t\ln t\,dt = \tfrac{t^2}{2}\ln t - \tfrac{t^2}{4} and ∫ln⁡t dt=tln⁡t−t\int\ln t\,dt = t\ln t - t. So u1=−t22ln⁡t+t24u_1 = -\tfrac{t^2}{2}\ln t + \tfrac{t^2}{4}, u2=tln⁡t−tu_2 = t\ln t - t, and

yp=e2t[−t22ln⁡t+t24+t2ln⁡t−t2]=t2e2t4 (2ln⁡t−3).y_p = e^{2t}\Bigl[-\tfrac{t^2}{2}\ln t + \tfrac{t^2}{4} + t^2\ln t - t^2\Bigr] = \frac{t^2e^{2t}}{4}\,(2\ln t - 3) .

Block B checks the residual (00) and RK45 started from the data of ypy_p at t=1t = 1 (−5.541792-5.541792 and −18.472640-18.472640): at t=2t = 2 both give −88.105343-88.105343, at t=3t = 3 both give −728.6911-728.6911.

A second route checks the mechanism. With s=2s = 2 a double root, the shift identity of the last lesson collapses to L[ue2t]=e2tu′′L[ue^{2t}] = e^{2t}u'', so y=ve2ty = ve^{2t} with v′′=ln⁡tv'' = \ln t, and two integrations give v=t22ln⁡t−34t2v = \tfrac{t^2}{2}\ln t - \tfrac34t^2 (block B confirms yp/e2t−v=0y_p/e^{2t} - v = 0). Variation of parameters found that double integral without noticing the shift; a finite guess fails because it cannot know it needs ln⁡t\ln t.

3. Both methods apply. y′′+6y′+8y=12e−3ty'' + 6y' + 8y = 12e^{-3t}. The roots are −2-2 and −4-4, so y1=e−2ty_1 = e^{-2t}, y2=e−4ty_2 = e^{-4t} and W=e−2t(−4e−4t)−(−2e−2t)e−4t=−2e−6tW = e^{-2t}(-4e^{-4t}) - (-2e^{-2t})e^{-4t} = -2e^{-6t}.

Variation of parameters. u1′=−e−4t⋅12e−3t−2e−6t=6e−tu_1' = -\dfrac{e^{-4t}\cdot12e^{-3t}}{-2e^{-6t}} = 6e^{-t}, so u1=−6e−tu_1 = -6e^{-t}; u2′=e−2t⋅12e−3t−2e−6t=−6etu_2' = \dfrac{e^{-2t}\cdot12e^{-3t}}{-2e^{-6t}} = -6e^{t}, so u2=−6etu_2 = -6e^{t}. Then yp=−6e−te−2t−6ete−4t=−12e−3ty_p = -6e^{-t}e^{-2t} - 6e^te^{-4t} = -12e^{-3t}.

Undetermined coefficients. −3-3 is not a root, P(−3)=9−18+8=−1P(-3) = 9 - 18 + 8 = -1, and yp=12/(−1) e−3t=−12e−3ty_p = 12/(-1)\,e^{-3t} = -12e^{-3t}.

They agree exactly here because the antiderivatives with no constant added happen to give −12e−3t-12e^{-3t}. Other constants would add c1e−2t+c2e−4tc_1e^{-2t} + c_2e^{-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 WW, u1u_1, u2u_2 and the sum from sympy.

From the formula to a kick

Integrate from a base time t0t_0 instead of using indefinite integrals: u1(t)=−∫t0ty2g/W dsu_1(t) = -\int_{t_0}^t y_2g/W\,ds and u2(t)=∫t0ty1g/W dsu_2(t) = \int_{t_0}^t y_1g/W\,ds. The factors y1(t)y_1(t) and y2(t)y_2(t) do not depend on ss, so they go inside the integrals:

yp(t)=∫t0tG(t,s) g(s) ds,G(t,s)=y1(s) y2(t)−y1(t) y2(s)W(s).y_p(t) = \int_{t_0}^{t} G(t,s)\,g(s)\,ds, \qquad G(t,s) = \frac{y_1(s)\,y_2(t) - y_1(t)\,y_2(s)}{W(s)} .

Two facts about GG follow directly. For fixed ss, as a function of tt it is a combination of y1(t)y_1(t) and y2(t)y_2(t), so G(⋅,s)G(\cdot,s) solves the homogeneous equation. And

G(s,s)=y1(s)y2(s)−y1(s)y2(s)W(s)=0,∂G∂t(s,s)=y1(s)y2′(s)−y1′(s)y2(s)W(s)=1.G(s,s) = \frac{y_1(s)y_2(s) - y_1(s)y_2(s)}{W(s)} = 0, \qquad \frac{\partial G}{\partial t}(s,s) = \frac{y_1(s)y_2'(s) - y_1'(s)y_2(s)}{W(s)} = 1 .

Block A has sympy confirm both for arbitrary y1,y2y_1, y_2.

Why this is a kick. Suppose a short push gg acts on [s,s+Δ][s, s+\Delta]. Integrating y′′=g−py′−qyy'' = g - py' - qy over that short interval, the right side’s second and third terms are bounded, so y′y' gains about g(s)Δg(s)\Delta while the push changes yy itself only by an amount of order Δ2\Delta^2 (the extra distance covered while the extra velocity builds up). The push is a jump in velocity of size g(s)Δg(s)\Delta, nothing else. After it the equation is homogeneous, with data (y,y′)=(0,g(s)Δ)(y, y') = (0, g(s)\Delta) at time ss. By linearity that solution is g(s)Δg(s)\Delta times the one with data (0,1)(0, 1), and the two properties above say that solution is G(t,s)G(t,s). So G(t,s)G(t,s) is the response at time tt to a unit kick at time ss, and the formula adds up all the kicks:

yp(t)≈∑kG(t,sk) g(sk) Δs,y_p(t) \approx \sum_k G(t, s_k)\,g(s_k)\,\Delta 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), ddt∫t0tF(t,s) ds=F(t,t)+∫t0t∂tF ds\frac{d}{dt}\int_{t_0}^tF(t,s)\,ds = F(t,t) + \int_{t_0}^t\partial_tF\,ds, and G(t,t)=0G(t,t) = 0, so

yp′=∫t0t∂tG g ds,yp′′=∂tG(t,t) g(t)+∫t0t∂t2G g ds=g(t)+∫t0t∂t2G g ds.y_p' = \int_{t_0}^t\partial_tG\,g\,ds, \qquad y_p'' = \partial_tG(t,t)\,g(t) + \int_{t_0}^t\partial_t^2G\,g\,ds = g(t) + \int_{t_0}^t\partial_t^2G\,g\,ds .

Since ∂t2G=−p ∂tG−qG\partial_t^2G = -p\,\partial_tG - qG, we get yp′′+pyp′+qyp=gy_p'' + py_p' + qy_p = g, with yp(t0)=yp′(t0)=0y_p(t_0) = y_p'(t_0) = 0. This second proof does not use the system for u1′,u2′u_1', u_2'. The partial derivative ∂tG\partial_tG holds ss fixed, as in 2.1 Functions of Several Variables & Partial Derivatives.

Constant coefficients: only t−st - s matters. If p,qp, q are constants, shifting time does not change the equation, so G(t,s)G(t,s) depends on τ=t−s\tau = t - s alone. From the roots of 5.2 Constant Coefficients & the Characteristic Equation:

rootsG(τ)G(\tau)
distinct real r1,r2r_1, r_2er1τ−er2τr1−r2\dfrac{e^{r_1\tau} - e^{r_2\tau}}{r_1 - r_2}
repeated rrτerτ\tau e^{r\tau}
α±iβ\alpha \pm i\betaeατsin⁡βτβ\dfrac{e^{\alpha\tau}\sin\beta\tau}{\beta}

For distinct real roots, put y1=er1ty_1 = e^{r_1t}, y2=er2ty_2 = e^{r_2t}, W(s)=(r2−r1)e(r1+r2)sW(s) = (r_2 - r_1)e^{(r_1 + r_2)s} in GG: the numerator is er1s+r2t−er1t+r2se^{r_1s + r_2t} - e^{r_1t + r_2s} and dividing gives (er2(t−s)−er1(t−s))/(r2−r1)(e^{r_2(t-s)} - e^{r_1(t-s)})/(r_2 - r_1), the first row. For example 3, G(τ)=12(e−2τ−e−4τ)G(\tau) = \tfrac12(e^{-2\tau} - e^{-4\tau}), and the solution with y(0)=y′(0)=0y(0) = y'(0) = 0 is

∫0t12(e−2(t−s)−e−4(t−s)) 12e−3s ds=6e−2t−12e−3t+6e−4t.\int_0^t\tfrac12\bigl(e^{-2(t-s)} - e^{-4(t-s)}\bigr)\,12e^{-3s}\,ds = 6e^{-2t} - 12e^{-3t} + 6e^{-4t} .

It is the guess’s −12e−3t-12e^{-3t} plus the homogeneous part 6e−2t+6e−4t6e^{-2t} + 6e^{-4t} that cancels the starting values (initial conditions last). Block C prints y(1)=0.32446071y(1) = 0.32446071 from the integral of GgGg, from this closed form and from RK45, with residual 00 and start values 0,00, 0.

A preview. For constant coefficients yp(t)=∫0tG(t−s) g(s) dsy_p(t) = \int_0^tG(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 GG is the impulse response. The Laplace module (impulses and delta, convolution and transfer function) turns the convolution into a product.

Play with it

◆ Interactive Cut 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=1y'' + 0.6y' + 4y = 1 (a steady push switched on at t=0t = 0), y(0)=y′(0)=0y(0) = y'(0) = 0, N=12N = 12 kicks of width 10/1210/12. The top strip draws gg and the kicks g(sk)Δsg(s_k)\Delta s; the main plot draws each kick’s own ring-down G(t−sk)g(sk)ΔsG(t - s_k)g(s_k)\Delta s (for N≤30N \le 30), their sum, and the RK4 reference, which the readout checks against itself at half the step (a gap of order 10−1210^{-12}). The readout gives the largest error over the time grid, the error with 2N2N kicks, and their ratio: at N=12N = 12, 1.996×10−11.996\times10^{-1} against 9.207×10−29.207\times10^{-2} at 2N=242N = 24, ratio 2.1682.168. Press Double N: the table lists the error for N=2,4,…,1024N = 2, 4, \dots, 1024 for both placements, and the log-log plot adds guide lines of slope −1-1 and −2-2 (guides only).

For the steady push the left-kick ratio from N/2N/2 to NN is 2.0132.013, 2.0082.008, 2.0032.003 at N=256,512,1024N = 256, 512, 1024: first order, the error halving when the width halves. For the 1-cosine gust it is 4.0054.005, 4.0034.003, 3.9993.999: second order. The difference is not a jump in gg (neither forcing has one) but the starting value, g(0)=1g(0) = 1 against g(0)=0g(0) = 0. Mechanism: on one piece [s,s+Δ][s, s+\Delta] the integrand F(s)=G(t−s)g(s)F(s) = G(t-s)g(s) has ∫F=F(s)Δ+12F′(s)Δ2+…\int F = F(s)\Delta + \tfrac12F'(s)\Delta^2 + \dots, so the left-kick sum misses about 12F′Δ2\tfrac12F'\Delta^2 per piece, and over all pieces 12Δ∫F′ ds=12Δ (F(t)−F(0))\tfrac12\Delta\int F'\,ds = \tfrac12\Delta\,(F(t) - F(0)). Since F(t)=G(0)g(t)=0F(t) = G(0)g(t) = 0 and F(0)=G(t)g(0)F(0) = G(t)g(0), the first-order error is about 12Δ ∣G(t)∣ ∣g(0)∣\tfrac12\Delta\,|G(t)|\,|g(0)|: it comes from the first kick alone and vanishes when g(0)=0g(0) = 0. Block E tests it: with max⁡G=0.403080\max G = 0.403080, the estimate (T/2N)max⁡G(T/2N)\max G is 1.5745×10−21.5745\times10^{-2} at N=128N = 128 and 1.9682×10−31.9682\times10^{-3} at N=1024N = 1024, against measured left-kick errors 1.5963×10−21.5963\times10^{-2} and 1.9718×10−31.9718\times10^{-3}.

Tick midpoint kicks: expanding FF about the middle of a piece, odd terms cancel and the per-piece error is of order Δ3\Delta^3. The table ratios are between 3.7483.748 and 4.3904.390 at N=256,512,1024N = 256, 512, 1024 for the push and between 3.7433.743 and 4.3534.353 for the gust, scattered around 44 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.5781.578 to 3.1563.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)y'' + y = 1/(1+t^2) with y(0)=y′(0)=0y(0) = y'(0) = 0 (y1=cos⁡y_1 = \cos, y2=sin⁡y_2 = \sin, W=1W = 1):

y(T)=sin⁡T∫0Tcos⁡s1+s2 ds−cos⁡T∫0Tsin⁡s1+s2 ds.y(T) = \sin T\int_0^T\frac{\cos s}{1 + s^2}\,ds - \cos T\int_0^T\frac{\sin s}{1 + s^2}\,ds .

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\int_0^3 = 0.624404 and 0.7151130.715113, so y(3)=0.7960722734y(3) = 0.7960722734; RK45 gives 0.79607227340.7960722734 too, a gap of 2.52×10−122.52\times10^{-12}. scipy.integrate.quad used 105105 evaluations of gg; RK45 at tolerance 10−1110^{-11} made 10101010 calls, and at 10−810^{-8} it made 272272 with an error of 2.64×10−92.64\times10^{-9} in y(3)y(3).

For yy at many times, use the separable form G(t,s)=(y1(s)y2(t)−y1(t)y2(s))/W(s)G(t,s) = (y_1(s)y_2(t) - y_1(t)y_2(s))/W(s): the integrands do not depend on tt, so one pass of two cumulative trapezoid sums over 30013001 points (30013001 evaluations of gg) gives yy at all of them, with a gap to RK45 of 9.08×10−89.08\times10^{-8} (the trapezoid rule’s second-order error, from memory, plus RK45’s). The price is that you need y1y_1 and y2y_2 in closed form, which RK45 does not.

Where the method stops

  1. It needs y1y_1 and y2y_2 in closed form. For the Airy equation y′′−ty=0y'' - 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.
  2. The integrals may not be elementary, as in the 1/(1+t2)1/(1 + t^2) example: the method is correct, but the answer is a number from quadrature.
  3. The solution may not exist where you want it: the sec⁡t\sec t answer lives on (−π/2,π/2)(-\pi/2, \pi/2).
  4. It is linear. For y′′+y2=gy'' + y^2 = g the response to two kicks is not the sum of the responses.
  5. The kick picture is a model, good only for pulses short against the system’s timescale (problem 2).

Lab

Blocks: A Cramer and GG for general y1,y2y_1, y_2; B the sec⁡t\sec t and ln⁡t\ln t 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′u_1', u_2'), 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
⌘/Ctrl + Enter

Problems

✏️ Pen & paperA repeated root and a negative power●●○

Solve y′′−6y′+9y=e3t/t2y'' - 6y' + 9y = e^{3t}/t^2 for t>0t \gt 0 with y(1)=e3y(1) = e^3, y′(1)=4e3y'(1) = 4e^3. Check the particular solution with the shift identity.

Show worked solution

P(r)=(r−3)2P(r) = (r - 3)^2, so y1=e3ty_1 = e^{3t}, y2=te3ty_2 = te^{3t} and W=e3t(1+3t)e3t−3e3t⋅te3t=e6tW = e^{3t}(1 + 3t)e^{3t} - 3e^{3t}\cdot te^{3t} = e^{6t}. With g=e3t/t2g = e^{3t}/t^2:

u1′=−te3t⋅e3t/t2e6t=−1t,u2′=e3t⋅e3t/t2e6t=1t2.u_1' = -\frac{te^{3t}\cdot e^{3t}/t^2}{e^{6t}} = -\frac1t, \qquad u_2' = \frac{e^{3t}\cdot e^{3t}/t^2}{e^{6t}} = \frac1{t^2} .

So u1=−ln⁡tu_1 = -\ln t, u2=−1/tu_2 = -1/t, and yp=−e3tln⁡t−e3ty_p = -e^{3t}\ln t - e^{3t}. The term −e3t-e^{3t} is homogeneous, so yp=−e3tln⁡ty_p = -e^{3t}\ln t also works. Shift check: with s=3s = 3 a double root, L[ve3t]=e3tv′′L[ve^{3t}] = e^{3t}v'', so v′′=1/t2v'' = 1/t^2 and v=−ln⁡tv = -\ln t plus a line.

General solution y=−e3tln⁡t+(c1+c2t)e3ty = -e^{3t}\ln t + (c_1 + c_2t)e^{3t}. Impose the data on the sum: y(1)=(c1+c2)e3=e3y(1) = (c_1 + c_2)e^3 = e^3 gives c1+c2=1c_1 + c_2 = 1. With y′=e3t[3(−ln⁡t+c1+c2t)−1/t+c2]y' = e^{3t}\bigl[3(-\ln t + c_1 + c_2t) - 1/t + c_2\bigr], y′(1)=e3[3−1+c2]=4e3y'(1) = e^3[3 - 1 + c_2] = 4e^3 gives c2=2c_2 = 2, c1=−1c_1 = -1:

y=e3t(2t−1−ln⁡t).y = e^{3t}(2t - 1 - \ln t) .

Block F confirms residual 00, the two data values and y(2)=e6(3−ln⁡2)=930.6508y(2) = e^6(3 - \ln2) = 930.6508.

✏️ Pen & paperWhen is a pulse a kick?●●○

A mass-spring y′′+25y=g(t)y'' + 25y = g(t) (natural frequency ω=5\omega = 5) starts at rest and receives g=10g = 10 for 0≤t≤0.40 \le t \le 0.4, then g=0g = 0. (a) Use G(τ)=sin⁡(5τ)/5G(\tau) = \sin(5\tau)/5 to find y(t)y(t) for t>0.4t \gt 0.4 and its amplitude. (b) Compare with a single ideal kick of the same area at t=0t = 0. (c) How short must the pulse be for the amplitude to be within 1%1\% of the kick’s?

Show worked solution

(a) For t>0.4t \gt 0.4: y=∫00.4sin⁡5(t−s)5 10 ds=2∫00.4sin⁡5(t−s) ds=25[cos⁡5(t−s)]s=00.4=25(cos⁡5(t−0.4)−cos⁡5t)y = \int_0^{0.4}\tfrac{\sin5(t-s)}{5}\,10\,ds = 2\int_0^{0.4}\sin5(t-s)\,ds = \tfrac25\bigl[\cos5(t-s)\bigr]_{s=0}^{0.4} = \tfrac25\bigl(\cos5(t - 0.4) - \cos5t\bigr). Sum to product, cos⁡A−cos⁡B=−2sin⁡A+B2sin⁡A−B2\cos A - \cos B = -2\sin\frac{A+B}2\sin\frac{A-B}2 with A=5t−2A = 5t - 2, B=5tB = 5t:

y=45sin⁡(1) sin⁡(5t−1).y = \tfrac45\sin(1)\,\sin(5t - 1) .

The amplitude is 0.8sin⁡1=0.6731770.8\sin1 = 0.673177. Check: y(2)=0.673177sin⁡9=0.277429y(2) = 0.673177\sin9 = 0.277429, and RK45 with the pulse switched off at 0.40.4 gives 0.2774290.277429 (block F).

(b) The area is 10×0.4=410\times0.4 = 4, so a kick at t=0t = 0 gives y=45sin⁡5ty = \tfrac45\sin5t with amplitude 0.80.8. The pulse gives 0.8⋅sin⁡(1)/10.8\cdot\sin(1)/1, i.e. 0.8414710.841471 of that, and the phase 5t−1=5(t−0.2)5t - 1 = 5(t - 0.2) is that of a kick at the centre of the pulse, t=0.2t = 0.2.

(c) In general the amplitude ratio is sin⁡(x)/x\sin(x)/x with x=ωD/2x = \omega D/2. It equals 0.990.99 at x=0.24532x = 0.24532, so D=2x/ω=0.09813D = 2x/\omega = 0.09813 s: under a tenth of a second, under a twelfth of the natural period 2π/5=1.25662\pi/5 = 1.2566 s.

✏️ Pen & paperVariable coefficients: divide first●●●

Solve t2y′′+ty′−y=t2ln⁡tt^2y'' + ty' - y = t^2\ln t for t>0t \gt 0. (a) Show that y1=ty_1 = t and y2=1/ty_2 = 1/t solve the homogeneous equation and find WW and check it with Abel’s theorem. (b) Find a particular solution. (c) Say what goes wrong if you use g=t2ln⁡tg = t^2\ln t.

Show worked solution

(a) y=ty = t: 0+t−t=00 + t - t = 0. y=1/ty = 1/t: t2⋅2/t3+t(−1/t2)−1/t=2/t−1/t−1/t=0t^2\cdot2/t^3 + t(-1/t^2) - 1/t = 2/t - 1/t - 1/t = 0. W=t⋅(−1/t2)−1⋅(1/t)=−2/tW = t\cdot(-1/t^2) - 1\cdot(1/t) = -2/t. Standard form has p=1/tp = 1/t, and Abel gives W∝e−∫p=1/tW \propto e^{-\int p} = 1/t, consistent with −2/t-2/t.

(b) Standard form: y′′+y′/t−y/t2=ln⁡ty'' + y'/t - y/t^2 = \ln t, so g=ln⁡tg = \ln t. Then

u1′=−y2gW=−(1/t)ln⁡t−2/t=12ln⁡t,u2′=y1gW=tln⁡t−2/t=−12t2ln⁡t.u_1' = -\frac{y_2g}{W} = -\frac{(1/t)\ln t}{-2/t} = \tfrac12\ln t, \qquad u_2' = \frac{y_1g}{W} = \frac{t\ln t}{-2/t} = -\tfrac12t^2\ln t .

By parts: u1=12(tln⁡t−t)u_1 = \tfrac12(t\ln t - t) and u2=−12(t33ln⁡t−t39)u_2 = -\tfrac12\bigl(\tfrac{t^3}{3}\ln t - \tfrac{t^3}{9}\bigr). Then yp=tu1+u2/t=12t2ln⁡t−12t2−16t2ln⁡t+118t2=13t2ln⁡t−49t2=t2(3ln⁡t−4)9y_p = tu_1 + u_2/t = \tfrac12t^2\ln t - \tfrac12t^2 - \tfrac16t^2\ln t + \tfrac1{18}t^2 = \tfrac13t^2\ln t - \tfrac49t^2 = \dfrac{t^2(3\ln t - 4)}{9}. Block F checks the residual (00) and prints yp(2)=−0.853582y_p(2) = -0.853582, yp(4)=0.282459y_p(4) = 0.282459; RK45 from the data of ypy_p at t=1t = 1 gives the same.

(c) gg must be what sits on the right of the standard form. With g=t2ln⁡tg = t^2\ln t you would be solving y′′+y′/t−y/t2=t2ln⁡ty'' + y'/t - y/t^2 = t^2\ln t, which is t2y′′+ty′−y=t4ln⁡tt^2y'' + ty' - y = t^4\ln t once multiplied back by t2t^2: a different equation, so the ypy_p 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?

✅ 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.

✅ Concept check

To use $u_1' = -y_2g/W$ on $t^2y'' + ty' - y = 5t$, which $g$ should you use?

Key Takeaways

  • Variation of parameters keeps yp=u1y1+u2y2y_p = u_1y_1 + u_2y_2 and lets the constants move; the condition u1′y1+u2′y2=0u_1'y_1 + u_2'y_2 = 0 is a free choice because the Wronskian matrix is invertible.
  • Cramer’s rule on the 2×22\times2 system gives u1′=−y2g/Wu_1' = -y_2g/W and u2′=y1g/Wu_2' = y_1g/W for y′′+py′+qy=gy'' + py' + qy = g in standard form; divide by the leading coefficient first.
  • It solves what guessing cannot, such as sec⁡t\sec t (answer cos⁡tln⁡cos⁡t+tsin⁡t\cos t\ln\cos t + t\sin t) and e2tln⁡te^{2t}\ln t, and agrees with the guess where both apply; constants of integration only add homogeneous solutions.
  • yp=∫t0tG(t,s)g(s) dsy_p = \int_{t_0}^tG(t,s)g(s)\,ds, and G(⋅,s)G(\cdot,s) solves the homogeneous equation with G(s,s)=0G(s,s) = 0, ∂tG(s,s)=1\partial_tG(s,s) = 1: the response to a unit kick at time ss. For constant coefficients GG depends on t−st - s only.
  • A sum of NN kicks converges to the response; left kicks are first order when g(0)≠0g(0) \neq 0 (measured ratio 2.0032.003 at N=1024N = 1024) and second order when g(0)=0g(0) = 0 (3.9993.999), and a pulse acts as a kick only if it is short against the system’s timescale.
  • Limits: closed-form y1,y2y_1, y_2 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.