Linear differential equations doubt There is solution below with the question, I have doubt in the last step.
Solve $$\frac{d^2 y}{dx^2} + 2y = x^2 e^{3x} - \cos 2x + $e^x$$
Solution: Auxillary equation is $D^2 + 2 = 0$
$$D=\pm i\sqrt{2}$$
Complementary function  is $e^{0x}(C_1 \cos \sqrt{2} x + C_2 \sin \sqrt{2}x)$
Particular Integral is $\frac{1}{f(D)}(X)$
\begin{align}
&= \frac{1}{(D^2+2)} e^x + \frac{1}{(D^2+2)} x^2 e^{3x} - \frac{1}{(D^2+2)} \cos2x\\
&= \frac{1}{(1^2+2)} e^x + \frac{1}{(D+3)^2 + 2} x^2 e^{3x} - \frac{1}{(-2)^2+2} \cos2x
\end{align}
Value of $D$ in the last step is $D=D+3$, $D=1$, $D=-2$.
Why is it that the value of $D$ keeps on changing for every part in the equation?
Kindly help.

$$
u=(D^2+2)^{-1}(x^2·e^{ 3x})
$$
is just a fancy way to say that $u$ is a solution of
$$
u''+2u=x^2·e^{ 3x}
$$
which does not tell you much. You could then use a trial solution with undetermined coefficients $$u=(A+Bx+Cx^2)e^{3x}$$ to get
$$
u''+2u=e^{3x}(9(A+Bx+Cx^2)+6(B+2Cx)+2C+2(A+Bx+Cx^2))\\
=(11A+6B+2C+(11B+12C)x+11Cx^2)e^{3x}
$$
and comparing coefficients of like expressions
one gets backwards $C=\frac1{11}$, $B=-\frac{12}{11^2}$, $A=\frac{50}{11^3}$.

If one wants to get a more complicated way, write $x^2e^{3x}=\frac{∂^2}{∂^2α}e^{(3+α)x}{}_{\Big|α=0}$ so that the inversion becomes
$$
\frac{∂^2}{∂^2α}\frac{e^{(3+α)x}}{(3+α)^2+2}{}_{\Big|α=0}\\
=\frac{∂^2}{∂^2α}\left(e^{3x}(1+αx+\tfrac12(αx)^2)·\frac1{11}·(1-\tfrac{α(6+α)}{11}+\tfrac{α^2(6+α)^2}{11^2})+O(α^3)\right)_{\Big|α=0}
$$
which comes close to the indicated formalism.
