The method of undetermined coefficients

Suppose we want to know the general solution  for the differential equation\(\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 
    \(y'\)'\  + \ 2  y'\  + \ 5  y\  = \ 
      te\^\(t\ \) - \ 
        2  sin\ 3  t . \ \ 
First\ we\ would\ need\ to\ find\ some\ 
          particular\ solution\)by taking a guess at its form .   We will try \(\ \ \ \ \ \ \ \ \ 
    y\_0\  = \ 
      Ate\^t\  + \ Be\^t\  + \ C\ sin\ [3  t]\  + \ D\ \(cos[3  t] . \)

    \ \ \ \ \ \ \ \ \ \)

y0  =  
      a t Exp[t]  +  b Exp[t]  +  c Sin[3  t]  +  d Cos[3  t]

Plugging this function into the left side of our \(differential\ equation\ gives
\)

leftside  =  D[y0, t, t]  +  2  D[y0, t]  +  5 y0

leftside  =  Simplify[leftside]

Equating this with the right side of of ourdifferential equation gives us the following\(system\ of\ equations\ to\ 
        \(solve : 
\ \ \ \ \ \ \ \ \ 		6  C\  - \ 4  D\)\  = \ 
      \(0
\ \ \ \ \ \ \ \ \  - 4\ C\  - \ 6\ D\  = \ 
        \(\(-2\)
\ \ \ \ \ \ \ \ \ \ \ \ \ 4\ A\  + \ 8  B\  = \ 0\)\)\)\(\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 8\ A\  = \ 1
\)

\(Solve[{6  c\  - \ 4  d\  == \ 0, \ \(-4\) c\  - \ 6  d\  == \ \(-2\), \ 
        4  a\  + \ 8  b == \ 0, 
		\ \ \ \ \ \ \ \ \ \ 8  a\  == \ 1}, {a, 
        b, c, d}]\)

Now we substitute these values into our expression for\(\(\(y\_0\) : \)
	\)

y0  = y0  /.  Part[%, 1]

This gives us a particular solution to] our differential equation .   The general solution isgiven by            y  =  (Subscript[y, 0]) +  (Subscript[y, h])where (Subscript[y, h]) is the general solution of the correspondinghomogeneous equation           y''  +  2  y'  +  5  y =  0. Hence we must solve the characteristic equation           (r^2)  +  2  r  +  5  = 0. This can be done by hand or by

Solve[{r^2 + 2  r + 5 == 0}, {r}]

\(\(In\ either\ case, \ we\ get
\)\)

yh  =  Exp[-t] (c1 Cos[2  t]  +  c2 Sin[2  t])

and finally,  we obtain the general solution to our\(differential\ equation
\)

y  = yh  +  y0

We check this by plugging back into our original\(differential\ equation
\)

leftside  =  Simplify[D[y, t, t]  +  2  D[y, t]  +  5  y]

...  which is what we wanted .