Method of Undetermined Coefficients

April 13, 2026

Problem

Solve y'' + y = sin(2x). Guess y_p = A sin(2x) + B cos(2x), determine A and B, then combine with the homogeneous solution.

Explanation

What is undetermined coefficients for?

For a non-homogeneous linear ODE ay+by+cy=g(x),a y'' + b y' + c y = g(x), the general solution has the form y=yh+ypy = y_h + y_p where

  • yhy_h is the homogeneous solution (general solution of the ODE with gg replaced by 00), and
  • ypy_p is any particular solution of the full non-homogeneous equation.

Why this works: if LL denotes the linear operator on the left (Ly=ay+by+cyL y = a y'' + b y' + c y), then Lyh=0L y_h = 0 and Lyp=gL y_p = g, so L(yh+yp)=0+g=gL(y_h + y_p) = 0 + g = g. Any particular ypy_p does the trick — we just need one.

The method of undetermined coefficients is the fastest way to find ypy_p when g(x)g(x) is one of a few "nice" forms — polynomials, exponentials, sines/cosines, and products of these. You guess a function of the same form as gg (with unknown coefficients) and plug in to determine the coefficients.

Limitation: only works for those special right-hand sides. For arbitrary gg, use variation of parameters (see #187).

The given equation

y+y=sin(2x)y'' + y = \sin(2 x)

Step 1 — Find the homogeneous solution

y+y=0y'' + y = 0: characteristic equation r2+1=0    r=±ir^{2} + 1 = 0 \implies r = \pm i (see #184). yh(x)=C1cosx+C2sinx.y_h(x) = C_1 \cos x + C_2 \sin x.

Step 2 — Guess the particular solution

The right side is sin2x\sin 2x. The derivatives of sin2x\sin 2x and cos2x\cos 2x stay inside the 2D span {sin2x,cos2x}\{\sin 2x, \cos 2x\}, so the right guess is yp=Asin2x+Bcos2xy_p = A \sin 2x + B \cos 2x (even though the RHS only has sin2x\sin 2x, the derivatives will bring in cos2x\cos 2x and we need both coefficients to balance).

Important check — resonance. Before committing to this guess, check that it's not already a homogeneous solution. Here yhy_h has frequency 11 (cosx,sinx\cos x, \sin x) while the guess has frequency 22 — no overlap. ✓ If there were overlap, we'd multiply by xx (or higher powers) to escape. More on this below.

Step 3 — Compute ypy_p' and ypy_p''

yp=2Acos2x2Bsin2xy_p' = 2 A \cos 2x - 2 B \sin 2x yp=4Asin2x4Bcos2xy_p'' = -4 A \sin 2x - 4 B \cos 2x

Step 4 — Substitute into the ODE and match coefficients

yp+yp=(4Asin2x4Bcos2x)+(Asin2x+Bcos2x)y_p'' + y_p = (-4 A \sin 2x - 4 B \cos 2x) + (A \sin 2x + B \cos 2x) =3Asin2x3Bcos2x= -3 A \sin 2x - 3 B \cos 2x

Set equal to the right side sin2x=1sin2x+0cos2x\sin 2x = 1 \cdot \sin 2x + 0 \cdot \cos 2x:

  • sin2x\sin 2x coefficient: 3A=1    A=13-3 A = 1 \implies A = -\dfrac{1}{3}.
  • cos2x\cos 2x coefficient: 3B=0    B=0-3 B = 0 \implies B = 0.

Step 5 — Assemble particular solution. yp(x)=13sin2x.y_p(x) = -\frac{1}{3} \sin 2x.

Step 6 — General solution

y(x)=C1cosx+C2sinx13sin2x\boxed{\, y(x) = C_1 \cos x + C_2 \sin x - \tfrac{1}{3} \sin 2x \,}

Verification

yp=13sin2xy_p = -\tfrac{1}{3} \sin 2x, so yp=43sin2xy_p'' = \tfrac{4}{3} \sin 2x. yp+yp=43sin2x13sin2x=sin2x  y_p'' + y_p = \tfrac{4}{3} \sin 2x - \tfrac{1}{3} \sin 2x = \sin 2x \; \checkmark

The guess-table for undetermined coefficients

Match the right side g(x)g(x) to the corresponding guess for ypy_p:

  • g=g = polynomial of degree nnyp=Anxn++A1x+A0y_p = A_n x^{n} + \ldots + A_1 x + A_0 (full polynomial of same degree).
  • g=eαxg = e^{\alpha x}yp=Aeαxy_p = A e^{\alpha x}.
  • g=sinβxg = \sin \beta x or cosβx\cos \beta xyp=Asinβx+Bcosβxy_p = A \sin \beta x + B \cos \beta x (both!).
  • g=eαxsinβxg = e^{\alpha x} \sin \beta x or eαxcosβxe^{\alpha x} \cos \beta xyp=eαx(Asinβx+Bcosβx)y_p = e^{\alpha x}(A \sin \beta x + B \cos \beta x).
  • gg = product of the above → ypy_p = product of the corresponding guesses.
  • gg = sum of different forms → ypy_p = sum of corresponding guesses (solve each part separately).

The resonance fix — multiply by xsx^s

If your guess overlaps with yhy_h, it fails (plugging in gives 0=g0 = g, a contradiction). Fix: multiply the guess by the smallest xsx^s that eliminates the overlap.

Example. y+y=sinxy'' + y = \sin x. Now the guess Asinx+BcosxA \sin x + B \cos x is part of yhy_h — this is the resonant forcing. Upgrade: yp=x(Asinx+Bcosx).y_p = x (A \sin x + B \cos x).

Solving gives A=0A = 0, B=1/2B = -1/2, so yp=12xcosxy_p = -\tfrac{1}{2} x \cos x — the particular solution grows linearly because we're driving the oscillator at its natural frequency. This is the archetype of physical resonance: amplitude builds indefinitely.

Initial value problem

For our problem with y(0)=0y(0) = 0, y(0)=0y'(0) = 0:

y=C1cosx+C2sinx13sin2xy = C_1 \cos x + C_2 \sin x - \tfrac{1}{3} \sin 2x y(0)=C1=0y(0) = C_1 = 0 y=C1sinx+C2cosx23cos2xy' = -C_1 \sin x + C_2 \cos x - \tfrac{2}{3} \cos 2x y(0)=C223=0    C2=23y'(0) = C_2 - \tfrac{2}{3} = 0 \implies C_2 = \tfrac{2}{3}

y(x)=23sinx13sin2x.y(x) = \tfrac{2}{3} \sin x - \tfrac{1}{3} \sin 2x.

Common mistakes

  • Leaving out cos\cos when forcing is sin\sin. The derivative of sin\sin is cos\cos; the guess must be a full linear combination of both.
  • Not checking resonance. Plug in the homogeneous solutions y1,y2y_1, y_2 and see if your guess already solves Ly=0L y = 0. If yes, bump up by xx.
  • Using the wrong multiplicity of xx. A guess that matches a double homogeneous root needs x2x^{2}, not xx.
  • Forgetting to include yhy_h. The general solution is yh+ypy_h + y_p; ypy_p alone only works for zero initial conditions by coincidence.

Try it in the visualization

Sweep the forcing frequency and watch the amplitude of the particular solution. Cross the natural frequency of the oscillator — the amplitude blows up (mathematically reflected in the xsx^s resonance fix producing xcosω0xx \cos \omega_0 x / xsinω0xx \sin \omega_0 x growth).

Interactive Visualization

Parameters

2.00
1.00
0.00
0.67
20.00
3.00
Your turn

Got your own math or physics problem?

Turn any problem into an interactive visualization like this one — powered by AI, generated in seconds. Free to try, no credit card required.

Sign Up Free to Try It30 free visualizations every day
Method of Undetermined Coefficients | MathSpin