Finding particular solution when disturbance is $g(x)=\sin(2x)+\cos(3x)$ I have trouble with the following ODE: $$y''(x)+9y(x)=\sin(2x)+\cos(3x)$$
Solving the homogeneous equation is simple but I struggle making sense of the disturbance $g(x)=\sin(2x)+\cos(3x)$ when trying to find a particular solution. Mathematica seems to use $$y_p(x)=A\sin(2x)+Bx\sin(3x)$$ which apparently works but I have no idea why something like this is considered. I tried something similar to the right hand side and other combinations but nothing worked out. Especially the $x$ in the summand $Bx\sin(3x)$ confuses me as well as why no $\cos(\cdot)$ was chosen. The literature I have doesn't provide any tricks for disturbances of this form and I would very much like to know how mathematica came up with such an idea.
 A: Using the standard Ansatz $y(x)=\exp(\lambda x)$ we get that the (real) homogenous solution is of the type $$y_{\text{hom}}=c_1\cos(3 x)+c_2\sin(3 x)$$ for arbitrary $c_1,c_2\in\mathbb R$. Hence, the Wronskian is given by $$W(x)=\begin{vmatrix}\cos(3x)&\sin(3x)\\\frac{\mathrm d}{\mathrm dx}\cos(3x) & \frac{\mathrm d}{\mathrm dx}\sin(3x) \end{vmatrix}=3.$$
The particular solution will be given by $$v_1(x)\cos(3x)+v_2(x)\sin(3x)$$ where $$v_1(x)=-\int \frac{g(x)\sin(3x)}{W(x)}\,\mathrm dx$$ and $$v_2(x)=\int \frac{g(x)\cos(3x)}{W(x)}\,\mathrm dx.$$
Indeed, using product-to-sum identities, $$v_1(x)=-\frac13 \int\cos(3x)\sin(3x)+\sin(2x)\sin(3x)\,\mathrm dx=-\frac16\int \sin(6x)+\cos(x)-\cos(5x)\,\mathrm dx=\dots$$
and $$v_2(x)=\frac13\int \cos(3x)\cos(3x)+\cos(3x)\sin(2x)\,\mathrm dx=\frac16\int 1+\cos(6x)+\sin(5x)-\sin(x)\,\mathrm dx=\dots$$ which leads to the particular solution $$y(x)=\frac{1}{90} (5 \cos (3 x)+18 \sin (2 x)+15 x \sin (3 x)).$$ Can you take it from here now?
A: For an exam question, the best strategy in my opinion is a mix of undetermined constants method and complex approach. Split the DE into two equations since it's linear.
$$y''(x)+9y(x)=\sin(2x)+\cos(3x)$$
Solve the homogeneous part
$$r^2+9=0 \implies r=\pm 31 \implies y_h=c_1 cos(3x)+c_2 \sin(3x)$$
Since $\sin(2x)$ is not part of the homogeneous solution a good guess is
$$y_p=A \sin(2x)$$
$$\implies 5A\sin(2x)=\sin(2x) \implies A =\frac 1 5$$
$$y_p=\frac 1 5 \sin(2x)$$
Because at the LHS you d'ont have $y'$ term you don't need to bother with $B\cos(2x)$
Then for the $\cos (3x)$ try complex method. Rewrite the DE as:
$$y''(x)+9y(x)=e^{3ix}$$
And the guess should be:
$$y_p=Ax e^{3ix}$$
$$-9Ax e^{3ix}+6iA e^{3ix}+9Ax e^{3ix}=e^{3ix}$$
$$6iA =1 \implies A=-\frac i 6$$
So that
$$y_p=Ax e^{3ix}=-\frac i 6x e^{3ix}$$
$$y_p=-\frac i 6x (\cos(3x)+i\sin(3x))$$
Back to real world:
$$y=\Re \{y_p\}=\frac x 6 \sin(3x)$$
Finally:
$$ y(x)=c_1 cos(3x)+c_2 \sin(3x) +\frac x 6 \sin(3x)+\frac 1 5 \sin(2x)$$
