I have a very general question about the Method of Undetermined coefficients when the non-homogeneous part is a polynomial (say $n$th degree). In this case, I know that if you try:
$$ y\_p(x) = A\_nx^n+A\_{n-1}x^{n-1}+...+A\_1x+A\_0 $$

then you will be guaranteed to get the correct answer. However, when I look through solutions I find that my professor is often simplifying her choice by choosing $A\_i=0$ for some $i<n$.

Is there a way to know exactly when you can do this and when you have to assume that none of the $A\_i$ are zero?

If it helps to have a specific example, one I just saw was:
$$ x^2y''+xy'+y=x^4 $$
This is a standard Euler equation which can be solved from guessing $y=x^r$. Doing so gives, $r=\pm i$ and so our homogeneous solution is:
$$ y\_h(x) = c\_1 \cos(\ln x)+c\_2\sin(\ln x) $$
All of this I totally understand and can replicate. However, when she solves the non-homogeneous part she only chooses:
$$ y\_p(x) =Ax^4 $$
This is what I'm confused about. Is there something special about this problem that allows you to assume the particular solution is only a function of $x^4$?

Conversely, for the equation:
$$ y''-y'-2y=x $$
we can similarly just solve the characteristic equation to get $r=-1,2$. So our homogeneous solution is:
$$ y\_h(x) = c\_1e^{-x}+c\_2e^{2x} $$
Now in this example, however, she chooses:
$$ y\_p(x) = Ax+B $$
and after solving it turns out both are non-zero. What are the differences - is i.t because the first is an Euler equation? If so, why does that change things? Or are there no differences and I should just always assume $A\_i$ are nonzero?

Any help is much appreciated!