Chapter 4: Forced oscillators

The method of the flexible guess ("undetermined coefficients")

for finding a solution of an inhomogeneous linear differential equation

A first example: a 1st order equation with a polynomial inhomogeneity.

(1) Clear Maple's memory:

>    restart;

(2) Enter the differential equation:

>    diffeq:= diff(y(t),t)+2*y(t)=t^2+2*t;

diffeq := diff(y(t),t)+2*y(t) = t^2+2*t

(3) Enter your flexible guess at the solution, and plug it into the differential equation:

>    yGuess := a + b*t + c*t^2;
need := eval(subs( y(t)=yGuess, diffeq ));

yGuess := a+b*t+c*t^2

need := b+2*c*t+2*a+2*b*t+2*c*t^2 = t^2+2*t

We need this last equation to be true for all values of t, and the only way to ensure this is by

(4) making like terms balance on the two sides of the equation.

To get the constant terms   to balance,   we need

>    eq1:= b + 2*a = 0;

eq1 := b+2*a = 0

To get the t terms to balance, we need

>    eq2:= 2*c + 2*b = 2;

eq2 := 2*c+2*b = 2

To get the t^2 terms to balance, we need

>    eq3:= 2*c = 1;

eq3 := 2*c = 1

(5) Now we can solve these 3 requirements for the 3 undetermined coefficients, a,b,c:

>    sol:= solve({eq1,eq2,eq3},{a,b,c});

sol := {a = -1/4, b = 1/2, c = 1/2}

and so our answer is

>    ySolution := subs( sol, yGuess );

ySolution := -1/4+1/2*t+1/2*t^2

(6) We can check our work by plugging the supposed solution into the differential equation:

>    eval( subs( y(t)=ySolution, diffeq ) );

t^2+2*t = t^2+2*t

The LHS does equal the RHS, so our solution is good.

Getting Maple to pick out the coefficients of each kind of term

Instead of reading off the coefficients of each power of t ourselves, we can get Maple to do it.

Like this, for example:

>    eq1 := subs( t=0, need );
eq2 := subs( t=0, diff(need,t) );
eq3 := subs( t=0, diff(need,t,t) );

eq1 := b+2*a = 0

eq2 := 2*c+2*b = 2

eq3 := 4*c = 2

(Do you see why this works?)

Another example: a sinusoidally forced harmonic oscillator.

(1) Clear Maple's memory:

>    restart;

(2) Enter the differential equation:

>    diffeq:= diff(y(t),t,t)+3*diff(y(t),t)+2*y(t)=sin(3*t);

diffeq := diff(y(t),`$`(t,2))+3*diff(y(t),t)+2*y(t) = sin(3*t)

(3) Enter your guess at the solution (with undetermined coefficients), and plug it into the differential equation:

>    yGuess := a*sin(3*t) + b*cos(3*t);
need := eval(subs( y(t)=yGuess, diffeq ));

yGuess := a*sin(3*t)+b*cos(3*t)

need := -7*a*sin(3*t)-7*b*cos(3*t)+9*a*cos(3*t)-9*b*sin(3*t) = sin(3*t)

(4) Equate like terms by doing the following substitutions:

>    eq1:=subs( sin(3*t)=0,cos(3*t)=1,need);
eq2:=subs( sin(3*t)=1,cos(3*t)=0,need);

eq1 := -7*b+9*a = 0

eq2 := -7*a-9*b = 1

(5) Solve for a and b:

>    sol:=solve({eq1,eq2},{a,b});
ySolution:=subs(sol,yGuess);

sol := {a = -7/130, b = -9/130}

ySolution := -7/130*sin(3*t)-9/130*cos(3*t)

(6) Finally, check that our solution really is a solution:

>    eval( subs( y(t)=ySolution, diffeq ) );

sin(3*t) = sin(3*t)

Yes, the LHS does equal the RHS, so our solution is good.

A trickier example.

(1) Clear Maple's memory:

>    restart;

>    diffeq:= diff(y(t),t,t)+4*y(t)=t^2*exp(-3*t)*sin(t);

diffeq := diff(y(t),`$`(t,2))+4*y(t) = t^2*exp(-3*t)*sin(t)

>    yGuess := (a*t^2+b*t+c)*exp(-3*t)*cos(t)
        + (d*t^2+e*t+f)*exp(-3*t)*sin(t);
need := expand(eval(subs( y(t)=yGuess, diffeq )));

yGuess := (a*t^2+b*t+c)*exp(-3*t)*cos(t)+(d*t^2+e*t+f)*exp(-3*t)*sin(t)

need := 2*a/exp(t)^3*cos(t)-12/exp(t)^3*cos(t)*a*t-6/exp(t)^3*cos(t)*b-4/exp(t)^3*sin(t)*a*t-2/exp(t)^3*sin(t)*b+12/exp(t)^3*cos(t)*a*t^2+12/exp(t)^3*cos(t)*b*t+12/exp(t)^3*cos(t)*c+6/exp(t)^3*sin(t)*a...
need := 2*a/exp(t)^3*cos(t)-12/exp(t)^3*cos(t)*a*t-6/exp(t)^3*cos(t)*b-4/exp(t)^3*sin(t)*a*t-2/exp(t)^3*sin(t)*b+12/exp(t)^3*cos(t)*a*t^2+12/exp(t)^3*cos(t)*b*t+12/exp(t)^3*cos(t)*c+6/exp(t)^3*sin(t)*a...
need := 2*a/exp(t)^3*cos(t)-12/exp(t)^3*cos(t)*a*t-6/exp(t)^3*cos(t)*b-4/exp(t)^3*sin(t)*a*t-2/exp(t)^3*sin(t)*b+12/exp(t)^3*cos(t)*a*t^2+12/exp(t)^3*cos(t)*b*t+12/exp(t)^3*cos(t)*c+6/exp(t)^3*sin(t)*a...

Do some substitution to facilitate picking off coefficients of like terms:

>    eq0:=subs(cos(t)=C,sin(t)=S,exp(t)=1,t^2=TT,need);

eq0 := 2*a*C-12*C*a*t-6*C*b-4*S*a*t-2*S*b+12*C*a*TT+12*C*b*t+12*C*c+6*S*a*TT+6*S*b*t+6*S*c+2*d*S-12*S*d*t-6*S*e+4*C*d*t+2*C*e+12*S*d*TT+12*S*e*t+12*S*f-6*C*d*TT-6*C*e*t-6*C*f = TT*S
eq0 := 2*a*C-12*C*a*t-6*C*b-4*S*a*t-2*S*b+12*C*a*TT+12*C*b*t+12*C*c+6*S*a*TT+6*S*b*t+6*S*c+2*d*S-12*S*d*t-6*S*e+4*C*d*t+2*C*e+12*S*d*TT+12*S*e*t+12*S*f-6*C*d*TT-6*C*e*t-6*C*f = TT*S

Now pick off coefficient of each kind of term:

>    eq1:=subs(C=1,S=0,TT=0,t=0,eq0);

eq1 := 2*a-6*b+12*c+2*e-6*f = 0

>    eq2:=subs(C=0,S=1,TT=0,t=0,eq0);

eq2 := -2*b+6*c+2*d-6*e+12*f = 0

>    eq3:=subs(C=0,S=0,TT=1,t=0,eq0);

eq3 := 0 = 0

>    eq4:=subs(C=0,S=0,TT=0,t=1,eq0);

eq4 := 0 = 0

>    eq5:=subs(C=1,S=0,TT=0,t=1,eq0);

eq5 := -10*a+6*b+12*c+4*d-4*e-6*f = 0

>    eq6:=subs(C=0,S=1,TT=0,t=1,eq0);

eq6 := -4*a+4*b+6*c-10*d+6*e+12*f = 0

>    eq7:=subs(C=1,S=0,TT=1,t=0,eq0);

eq7 := 14*a-6*b+12*c+2*e-6*d-6*f = 0

>    eq8:=subs(C=0,S=1,TT=1,t=0,eq0);

eq8 := -2*b+6*a+6*c+14*d-6*e+12*f = 1

There were 6 kinds of terms, giving us 6 (informative) equations in the 6 unknowns.

>    sol:=solve({eq1,eq2,eq5,eq6,eq7,eq8},{a,b,c,d,e,f});
ySolution:=subs(sol,yGuess);

sol := {f = 119/6750, e = 13/225, d = 1/15, c = 46/3375, b = 1/25, a = 1/30}

ySolution := (1/30*t^2+1/25*t+46/3375)*exp(-3*t)*cos(t)+(1/15*t^2+13/225*t+119/6750)*exp(-3*t)*sin(t)

Check the result:

>    eval( subs( y(t)=ySolution, diffeq ) );

1/15*exp(-3*t)*cos(t)-6*(1/15*t+1/25)*exp(-3*t)*cos(t)-2*(1/15*t+1/25)*exp(-3*t)*sin(t)+12*(1/30*t^2+1/25*t+46/3375)*exp(-3*t)*cos(t)+6*(1/30*t^2+1/25*t+46/3375)*exp(-3*t)*sin(t)+2/15*exp(-3*t)*sin(t)-...
1/15*exp(-3*t)*cos(t)-6*(1/15*t+1/25)*exp(-3*t)*cos(t)-2*(1/15*t+1/25)*exp(-3*t)*sin(t)+12*(1/30*t^2+1/25*t+46/3375)*exp(-3*t)*cos(t)+6*(1/30*t^2+1/25*t+46/3375)*exp(-3*t)*sin(t)+2/15*exp(-3*t)*sin(t)-...
1/15*exp(-3*t)*cos(t)-6*(1/15*t+1/25)*exp(-3*t)*cos(t)-2*(1/15*t+1/25)*exp(-3*t)*sin(t)+12*(1/30*t^2+1/25*t+46/3375)*exp(-3*t)*cos(t)+6*(1/30*t^2+1/25*t+46/3375)*exp(-3*t)*sin(t)+2/15*exp(-3*t)*sin(t)-...

That LHS hopefully simplifies to equal the RHS.

>    simplify( expand(eval( subs( y(t)=ySolution, diffeq ) )));

t^2*exp(-3*t)*sin(t) = t^2*exp(-3*t)*sin(t)

Yes, it does!  So our solution is good.

Resonance peaks dependence on damping

We can use the above method with Maple to observe the response of a damped harmonic oscillator to sinusoidal forcing as a function of forcing frequency and of the amout of damping.

>    restart:
diffeq:= diff(y(t),t,t)+k*diff(y(t),t)+25*y(t)=sin(w*t);

diffeq := diff(y(t),`$`(t,2))+k*diff(y(t),t)+25*y(t) = sin(w*t)

>    guess:=a*sin(w*t)+b*cos(w*t);
eq:=eval(subs(y(t)=guess,diffeq));

guess := a*sin(w*t)+b*cos(w*t)

eq := -a*sin(w*t)*w^2-b*cos(w*t)*w^2+k*(a*cos(w*t)*w-b*sin(w*t)*w)+25*a*sin(w*t)+25*b*cos(w*t) = sin(w*t)

>    eq1:=subs(sin(w*t)=1,cos(w*t)=0,eq);
eq2:=subs(sin(w*t)=0,cos(w*t)=1,eq);

eq1 := -a*w^2-k*b*w+25*a = 1

eq2 := -b*w^2+k*a*w+25*b = 0

>    sol:=solve({eq1,eq2},{a,b});

sol := {b = -k*w/(k^2*w^2+w^4-50*w^2+625), a = -(w^2-25)/(k^2*w^2+w^4-50*w^2+625)}

>    amplitude:=sqrt(simplify(subs(sol,a^2+b^2)));

amplitude := (1/(k^2*w^2+w^4-50*w^2+625))^(1/2)

>    funcs:={seq(amplitude,k={.1,.5,1,3,10})};
plot(funcs,w=0..8,0..0.5);

funcs := {(1/(-49*w^2+w^4+625))^(1/2), (1/(-41*w^2+w^4+625))^(1/2), (1/(50*w^2+w^4+625))^(1/2), (1/(-49.75*w^2+w^4+625))^(1/2), (1/(-49.99*w^2+w^4+625))^(1/2)}

[Maple Plot]

>