Undetermined Coefficients

By Therese Shelton

an instructional sample with detailed instructions on Mathematica included

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

Classify:  2nd order, linear, nonhomogenous.

First solve the associated homogeneous equation
y'' - 7/2 y' + 3/2 y = 0

homogeneous eqn is constant coefficient.

"ycu" is the complementary solution with unspecified value of r; "yc" is the complementary soln.
It's good practice to begin by clearing all variables used.

Clear[ycu,yc,c1,c2,x]

ycu[x_]:=(E^(r*x))

ycu''[x]-7/2 yc1'[x] + 3/2 yc1[x]

Factor[%]

use double equals in equations

Solve[(1/2) (-3+r) (-1+2 r)==0,r]

slash-period means to substitute in the following rules.

% means the result of the last calculation.  use it sparingly.  it applies to whatever you had Mathematica do last, even if it's in another file.  

taking a dot product is one way to get c1 y1 + c2 y2.

ycu[x]/.%

%.{c1,c2}

here's the same thing without parentheses, just using copy and paste.

ycu[x]/.{{r->(1/2)},{r->3}}

{(E^(x/2)),(E^(3 x))}.{c1,c2}

defining the complementary solution

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

Now for the nonhomoegenous portion

"ypu" is the particular solution with undetermined values of the coefficients; "yp" is the particular soln with the values.
It's good practice to begin by clearing all variables used.

Clear[ypu,yp,A1,A0,x, LIfcns]

g(x) is of type P1 E1.

ypu[x_]:= A1*x*(E^x) + A0 * (E^x)

Since no portion of yp is linearly dependent upon the portions of yc, we proceed with our initial guess. The linearly independent functions are {(e^x) ,x*(e^x)}

LIfcns={(E^x) ,x*(E^x)}

derivatives

ypu'[x]

Collect[yp1'[x],LIfcns]

ypu''[x]

Collect[ypu''[x],LIfcns]

sub yp1 into the DE (lhs) and collect like terms

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

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

Collect[-A0 (E^x)-((3 A1 (E^x))/2)-A1 (E^x) x,LIfcns]

equate coefficients of the linearly independent functions

lhs is (-A0-((3 A1)/2)) (e^x)-A1 (e^x) x
and the rhs is x(e^x) or (0)(e^x)+ (1) (e^x) x.
(e^x) x:  -A1   =  1
(e^x): (-A0-((3 A1)/2))  = 0.

note the double equals for an equation in Mathematica.

Solve[{ -A1   ==  1,-A0-((3 A1)/2)==0}]

ypu[x]/.{A0->(3/2),A1->-1}

yp[x_]:=((3 (E^x))/2)-(E^x) x

solution is yc + yp

yc[x] + yp[x]

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

First solve the associated homogeneous equation as before

yc[x]

Now for the nonhomoegenous portion

This time, g(x) is of type P1 E3. Our initial guess of yp= (A1*x + A0 )*(e^(3x))  is repeated by a portion of yc, so we multiply it by enough x's so that no portion of yc repeats yp.  In this case, multiplying by x is enough.

Clear[ypu,yp,A1,A0,x,LIfcns]

Expand[x(A1*x + A0 )*(E^(3x)) ]

ypu[x_]:=A0 (E^(3 x)) x+A1 (E^(3 x)) (x^2)

Since no portion of yp is linearly dependent upon the portions of yc, we proceed with our initial guess.  The linearly independent functions are {(e^x) ,x*(e^(3 x)),(x^2)*(e^(3 x))}.

LIfcns={(E^(3x)) ,x*(E^(3 x)),(x^2)*(E^(3 x))}

derivatives

ypu'[x]

Collect[ypu'[x],LIfcns]

ypu''[x]

Collect[ypu''[x],LIfcns]

sub ypu into the DE (lhs) and collect like terms

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

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

Collect[(5/2) A0 (E^(3 x))+2 A1 (E^(3 x))+5 A1 (E^(3 x)) x,LIfcns]

equate coefficients of the linearly independent functions

lhs is (((5 A0)/2)+2 A1) (e^(3 x))+5 A1 (e^(3 x)) x
and the rhs is x(e^(3x)) or (0)(e^(3x))+ (1) (e^(3x))  x + (0)(e^(3 x)) (x^2).
(e^(3x)):0=((5 A0)/2)+2 A1
 (e^(3x))  x :1=5 A1 
(e^(3 x)) (x^2) :0=0, which is true.

remember the double equals for an equation in Mathematica.

Solve[{ 0==((5 A0)/2)+2 A1,1==5 A1 }]

ypu[x]/.{A1->(1/5),A0->-(4/25)}

yp[x_]:=-(4/25) (E^(3 x)) x+(1/5) (E^(3 x)) (x^2)

solution is yc + yp

yc[x] + yp[x]

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

Clear[y]

We claim that the solution is

y[x_]:= yc[x] +( ((3 (E^x))/2)-(E^x) x )+(-(4/25) (E^(3 x)) x+(1/5) (E^(3 x)) (x^2))

y[x]

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

voila.

Example 4:  y'' - 7/2 y' + 3/2 y = sin(2x)

we have the same yc[x], but now g(x) is of type T2, though we must remember to say P0 T2.

Now for the nonhomoegenous portion

we have the same yc[x], but now g(x) is of type T2, though we must remember to say P0 T2, and we must have both sin  and cosine in our assumed solution.  No part of this repeats yc.

Clear[ypu,yp,A1,A0,x,LIfcns]

ypu[x_]:= A1*Sin[2x] + A0 * Cos[2x]

LIfcns={Sin[2x],Cos[2x]}

derivatives

ypu'[x]

ypu''[x]

sub ypu into the DE (lhs) and collect like terms

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

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

Collect[Expand[ypu''[x] -7/2 ypu'[x] + 3/2 ypu[x]],LIfcns]

equate coefficients of the linearly independent functions

lhs is (-((5 A0)/2)-7 A1) Cos[2 x]+(7 A0-((5 A1)/2)) Sin[2 x]
and the rhs is Sin[2 x] or (0)Cos[2 x]+ (1) Sin[2 x].
Cos[2 x]:0=-((5 A0)/2)-7 A1
Sin[2 x] :1=7 A0-((5 A1)/2)

remember the double equals for an equation in Mathematica.

Solve[{ 0==-((5 A0)/2)-7 A1,1==7 A0-((5 A1)/2) }]

ypu[x]/.{A0->(28/221),A1->-(10/221)}

yp[x_]:=(28/221) Cos[2 x]-(10/221) Sin[2 x]

solution is yc + yp

yc[x] + yp[x]