How to solve $y''+9y=-18\sin{3x}-18e^{3x}$? Here is my solution so far:
$$y''+9y=-18\sin{3x}-18e^{3x}$$
1.Find complementary soultion.$$y''+9y=0$$ assuming that solution will be in form $e^{kx}$, substitute $y=e^{kx}$,
$$k^2e^{kx}+9e^{kx}=0$$
$$e^{kx}(k^2+9)=0$$
$$k^2+9=0 \Rightarrow k=\pm 3i$$
So complementary solution is $y=C_1cos{3x}+C_2sin{3x}$
2.Determine particular solution of $y''+9y=-18\sin{3x}-18e^{3x}$, by method of undefined coefficients.
Particular solution will be the sum of particular solutions to $y''+9y=-18e^{3x}$ and
$y''+9y=-18\sin{3x}$.
Particular solution to first one will be in form $ y_{p_1}=a_1e^{3x}$
Now for particular solution of $y''+9y=-18\sin{3x}$, Wolframalpha suggested that it is $y_{p_2}=x(a_2(cos{3x}+a_3sin{3x}))$, where it is multiplied by $x$ because of $sin{3x}$ in complementary solution.
What is the purpose of that $x$ and what should I do next to solve this DE?
 A: your particular solution and complementary solution should be linearly independent.If you dont have x there, then $y_{p_2}=a_2(cos{3x}+a_3sin{3x})$ is as good as complementary solution $y=C_1cos{3x}+C_2sin{3x}$, therefore we need x to make them L.I.  
Now your particular is $y_p=y_{p_1}+y_{p_2}$ , substitute $y_p$ in your D.E. to find the value of constants $a_1,a_2,a_3$ .
A: From the homogeneous solution, you know that when you substitute $c_1 \cos 3x + c_2 \sin 3x$, you get zero.
The solution of the ODE also contains a $\sin 3x$ term.
How can you assure that you can find a particular solution that is not coincident (that is, it is linearly independent) with this homogeneous solution, such that when you take the derivatives, it survives?
The trick is to choose a particular solution and then multiply that particular solution by $x$, as you show. 
See the examples and table on Paul's Online Notes for more details.
How to proceed is to find the first and second derivative of $y_p = x(a \cos 3x + b \sin 3x)$, which yield:


*

*$y_p'' = \cos(3 x) (6 b-9 a x)-3 \sin(3 x) (2 a+3 b x)$

*$y_p' =  \sin(3 x) (b-3 a x)+\cos(3 x) (a+3 b x)$


Substitute those into the ODE and solve for the constants $a$ and $b$:
$$y'' + 9y =  -18 \sin(3 x) $$
You should get $a = 3, b= 0$ and the final solution is:
$$y(x) = c_1 \cos(3 x) + c_2 \sin(3 x)-e^{3 x}+ 3 x \cos(3 x)$$
