TITLE: Solution to the $\displaystyle \phi'' + 4\phi' + 3\phi = x \cos {3x}. $
QUESTION [6 upvotes]: I came across the following differential equation while practicing  $ \displaystyle \phi'' + 4\phi' + 3\phi  = x \cos {3x} .$
Now, I used VARIATION OF PARAMETERS to solve it. I found general solution the equation $ \displaystyle \phi'' + 4\phi' + 3\phi  = 0 $ to be $\displaystyle C_1 e^{-3x} + C_2 e^{-x}.$
Now we need to find two functions $\lambda \ \text{and} \ \nu $ such that $\displaystyle \lambda'e^{-3x} + \nu'e^{-x} = 0 $ and $\displaystyle -3\lambda'e^{-3x} - \nu'e^{-x} = x \cos {3x} .$
Then the general solution would be : $\displaystyle \lambda e^{-3x} + \nu e^{-x} .$
On solving I got : $$\displaystyle \lambda = -\frac {1}{2} \int x \cdot \cos{3x} \cdot e^{3x} \mathrm {d}x \\  \nu = \frac {1}{2} \int x \cdot \cos{3x} \cdot e^{x} \mathrm {d}x  $$
These integrals took me a long time to solve. I used the traditional DI method to solve for it.
Finally getting the answer as : $$ \displaystyle C_1 e^{-3x} + C_2 e^{-x} + \frac {x}{30} ( 2 \sin {3x} - \cos {3x}  ) + \frac {47}{1800}\cos {3x}  +\frac {19}{200}\sin {3x} .  $$
I want my answer to get verified and am open to some good way to the integral quickly.
Thank you in advance.

REPLY [4 votes]: You can also apply the method of undetermined coefficients to find the particular solution. The solution to the complementary differential equation   $\phi'' + 4\phi' + 3\phi=0$ is
$$\phi_c(x) =c_1e^{-3x}+c_2e^{-x}.$$
Thus to find the particular solution to $\phi'' + 4\phi' + 3\phi = x \cos {3x}$ we try a particular solution of the form
$$\phi_p(x)=(Ax+B)\cos(3x)+(Cx+D)\sin(3x).$$
Hence
$$\phi_p'(x)=(A + 3Cx + 3D)\cos(3 x)+(-3 A x - 3 B + C) \sin(3 x), $$
$$\phi_p''(x)= (-9 A x - 9 B + 6 C)\cos(3 x) +  (-6 A -9Cx-9D)\sin(3 x).$$
Plugging these into the differential equation gives
\begin{equation}
\begin{split}
(-6A+12C)x\cos(3x) +(-6C-12A)x\sin(3x)+(4A-6B+6C+12D)\cos(3x)\\
+(-6A-12B+4C-6D)\sin(3x)=x\cos(3x).
\end{split}
\end{equation}
Therefore by relating coefficients
$$-6C-12A =0 \implies C=-2A,$$
$$-6A+12C=1 \implies \boxed{A=-\frac{1}{30}}, \quad \boxed{C=\frac{1}{15}},$$
$$4A-6B+6C+12D=0 \implies -6B+12D = -\frac{4}{15}\implies D = \frac{B}{2} -\frac{1}{45},$$
$$-6A-12B+4C-6D=0 \implies -15B+\frac{2}{15}=-\frac{7}{15}\implies \boxed{B=\frac{1}{25}}, \quad \boxed{D= -\frac{1}{450}}.$$
So the particular solution becomes
$$\phi_p(x)=\left(-\frac{1}{30}x+\frac{1}{25}\right)\cos(3x)+\left(\frac{1}{15}x-\frac{1}{450}\right)\sin(3x).$$