Finding particular solutions of $y^{(4)} + 2y'' + y = x \sin x$ We have a non homogeneous ODE
 $$y^{(4)} + 2y'' + y = x \sin x$$
with characteristic equation I get $(l^2+1)^2 = 0$ so $l = -i ,i$ and so the answer of homogeneous ODE is a linear combination of $\sin x , \cos x , x \sin x , x\cos x$.
For finding the Particular solution first I assumed $y_p = (Ax+B)(C\sin x + D \cos x)$ and it didn't work. Then $y_p = x(Ax+B)(C\sin x + D \cos x)$ and it didn't work. At last, $y_p = x^2(Ax+B)(C\sin x + D \cos x)$ worked and the answer was $-1/24 x^3 \sin x -1/8 x^2 \cos x$ worked but it took a lot of time to find that the other two don't work.
I want to know is there any way to guess the leading $x^n$ term and not testing different situations? (In this case $n=2$) I know it can be solved with a way involving Wronskian and Cramer's rule (but that way needs a 4x4 determinant which takes time to calculate) but I want to solve with undetermined coefficients rule so I want to find a better way for guessing the answer format.
 A: $$y_p=(k_0+k_1x)(A\cos x+B\sin x)$$
but this should be checked with the complementary solution to prevent the similarity
the complementary solution was
$$y_c=c_1\sin x+c_2\cos x+c_3x\sin x+c_4x\sin x$$
so the particular solution will be
$$y_p=(k_0x^2+k_1x^3)(A\cos x+B\sin x)$$
A: You can use operator calculus to solve this iteratively. We have
$$[d’’+2d’+1]y=[d’+1][d’+1]y=[d’+1]w=x\sin x$$
Solve for $w$ then solve $[d’+1]y=w$.
A: Generally speaking when solving linear ODE


*

*your homogeneous equation has root $r$ with multiplicity $m$ .

*the full equation has a RHS of the form $P(x)e^{rx}$ with $P$ polynomial.



Then you need to search for a particular solution in the form $Q(x)e^{rx}$ with $Q$ polynomial and $$\deg(Q)=\deg(P)+m$$
Although since the homogeneous solution will already have vanishing terms $(C_0+C_1x+\cdots+C_{m-1}x^{m-1})e^{rx}$, you can ignore them in the polynomial Q.
In case of a linear combination of such terms in the RHS, you can also search for a linear combination of particular solutions for each.
Note: in the special case of $RHS = P(x)$, consider the root $r=0$ since $e^{rx}=1$, and the same rule applies.

In your case $\pm i$ are roots with multiplicity $m=2$.
Your polynomial $P(x)=x$ is of degree $1$ and $\sin(x)$ is a linear combination of $e^{ix},\ e^{-ix}$.
So we need to search for $Q_1(x)e^{ix}$ and $Q_2(x)e^{-ix}$ with $Q$ of degree $3$ while ignoring already vanishing terms $(ax+b)e^{\pm ix}$, meaning that we search for a particular solution of the form $$(ax^3+bx^2)e^{ix}+(cx^3+dx^2)e^{-ix}$$
Which itself is equivalent in searching for $$(ax^3+bx^2)(A\cos x+B\sin x)$$
A: Short answer: The power of $x$ added to the particular solution is exactly equal to the multiplicity of the characteristic root. In this case, $r=\pm i$ has a mutiplicity of $2$. Putting it all together
$$ y_p(x) = \underbrace{x^2}_{\text{multiplicity =2}}\ \underbrace{(Ax+b)}_{\text{ansatz for } "x"}\underbrace{(A\sin x + B\cos x)}_{\text{ansatz for } "\sin x"} $$
