Undetermined Coefficients

By Therese Shelton

an instructional sample with detailed instructions on Mathematica included

Example 5:  y'' - 7/2 y' + 3/2 y = (x^3) + (x^2) (e^(3x)) + x sin2x

Classify:  2nd order, linear, nonhomogenous with g(x) = (x^3) + (x^2) (e^(3x)) + x sin2x

We already solved the associated homogeneous equation y'' - 7/2 y' + 3/2 y = 0

Clear[y,x]
DSolve[y''[x] - 7/2 y'[x] + 3/2 y[x] == 0, y[x],x]

Clear[yc,c1,c2]
yc[x_]:=c1 (E^(x/2))+c2 (E^(3 x))

Now for the nonhomoegenous portions

we have the same yc[x], but now g(x) is of type P3 + P2 E3 + P1 T2. We can treat this as 3 problems for the 3 summands.  In other words, we can solve the DE with g1(x) = (x^3) , g2(x) =  (x^2) (e^(3x)) , and g3(x) = x sin2x; then we add the resulting particular solutions.

yp1 to match  g1(x) = (x^3)

if we omit the asterisk for multiplication, we must add a space.
here my variables are yp1 for the particular solution to the first piece of g(x) and yp1u for the undetermined version of yp1.

Clear[yp1u,yp1,LI1,A3,A2,A1,A0]
yp1u[x_]:= A3 x^3 + A2 x^2 + A1 x + A0
LI1={x^3 , x^2 , x,1 }

derivatives

yp1u'[x]

yp1u''[x]

sub into the DE (lhs) and collect like terms

yp1u''[x] -7/2 yp1u'[x] + 3/2 yp1u[x]

Expand[yp1u''[x] -7/2 yp1u'[x] + 3/2 yp1u[x]]

Collect[Expand[yp1u''[x] -7/2 yp1u'[x] + 3/2 yp1u[x]],LI1]

equate coefficients of the linearly independent functions

x^0:0=((3 A0)/2)-((7 A1)/2)+2 A2
x^1 :0=((3 A1)/2)-7 A2+6 A3
x^2: 0 = ((3 A2)/2)-((21 A3)/2)
x^3: 1 = ((3 A3)/2)

remember the double equals for an equation in Mathematica.

Solve[{0==((3 A0)/2)-((7 A1)/2)+2 A2,0==((3 A1)/2)-7 A2+6 A3, 0 == ((3 A2)/2)-((21 A3)/2), 1 == ((3 A3)/2) }]

yp1u[x]/.{A0->(1036/27),A1->(172/9),A2->(14/3),A3->(2/3)}

yp1[x_]:=(1036/27)+((172 x)/9)+((14 (x^2))/3)+((2 (x^3))/3)

yp2 to match  g2(x) =  (x^2) (e^(3x))

Since P2 E3 has a portion which repeats some of yc, we need to multiply the P2 E3 term by x^3 to get all terms "higher" than (x^2) (e^(3x)).

Clear[yp2,yp2u,LI2,B2,B1,B0]
Expand[( B2  x^2  (E^(3x)) + B1 x  (E^(3x)) + B0  (E^(3x))) x]

yp2u[x_]:= B0 (E^(3 x)) x+B1 (E^(3 x)) (x^2)+B2 (E^(3 x)) (x^3)
LI2 = Table[x^n (E^(3 x)), {n,0,3}]

derivatives

yp2u'[x]

Collect[%,LI2]

yp2u''[x]

Collect[%,LI2]

sub into the DE (lhs) and collect like terms

yp2u''[x] -7/2 yp2u'[x] + 3/2 yp2u[x]

Expand[yp2u''[x] -7/2 yp2u'[x] + 3/2 yp2u[x]]

Collect[Expand[yp2u''[x] -7/2 yp2u'[x] + 3/2 yp2u[x]],LI2]

equate coefficients of the linearly independent functions

LI2

(e^(3 x)):0=((5 B0)/2)+2 B1
(e^(3 x)) x:  0=5 B1+6 B2
(e^(3 x)) (x^2): 1=(15/2) B2
(e^(3 x)) (x^3) :0=0

remember the double equals for an equation in Mathematica.

Solve[{ 0==((5 B0)/2)+2 B1,0==5 B1+6 B2,1==(15/2) B2 }]

yp2u[x]/.{B0->(16/125),B1->-(4/25),B2->(2/15)}

yp2[x_]:=(16/125) (E^(3 x)) x-(4/25) (E^(3 x)) (x^2)+(2/15) (E^(3 x)) (x^3)

yp3 to match  g3(x)=x sin2x

g3(x) is of type P1 T2, and no portion of it is repeated by any part of yc.

Clear[yp3,yp3u,LI3,F1,F0,D1,D0]
yp3u[x_]:= D1 x Sin[2x] +D0  Sin[2x]+  F1 x  Cos[2x] + F0 Cos[2x]
LI3={Sin[2x],Cos[2x],x*Sin[2x],x*Cos[2x]}

derivatives

yp3u'[x]

Collect[%,LI3]

yp3u''[x]

Collect[%,LI3]

sub into the DE (lhs) and collect like terms

yp3u''[x] -7/2 * yp3u'[x] + 3/2 * yp3u[x]

Expand[%]

Collect[%,LI3]

equate coefficients of the linearly independent functions

Solve[{(-7 D0+4 D1-((5 F0)/2)-((7 F1)/2)) ==0,(-7 D1-((5 F1)/2)) ==0,(-((5 D0)/2)-((7 D1)/2)+7 F0-4 F1)==0,(-((5 D1)/2)+7 F1) ==1}]

yp3u[x]/.{D0->-(4634/48841),D1->-(10/221),F0->(776/48841),F1->(28/221)}

yp3[x_]:=((776 Cos[2 x])/48841)+(28/221) x Cos[2 x]-((4634 Sin[2 x])/48841)-(10/221) x Sin[2 x]

put it together

Clear[yp]
yp[x_] = yp1[x] + yp2[x] + yp3[x]

the general solution to the DE :

yc[x] + yp[x]