Integrate using the method of undetermined coefficients I was trying to solve this integral using the method of Undetermined Coefficients.
$$\int x^3\cos(3x)\,dx$$
My calculus book says:

We try:
$y=P(x)\cos(3x)+Q(x)\sin(3x)+C$, where $P(x)$ and $Q(x)$ are polynomials of degrees $m$ and $n$ respectively.
$y'=P'(x)\cos(3x)-3P(x)\sin(3x)+Q'(x)\sin(3x)+3Q'(x)\cos(3x)=x^3\cos(3x)$
Equating coefficients of like trigonometric functions, we find:
$P'(x)+3Q(x)=x^3$ and $Q'(x)-3P(x)=0$
The second of these equations requires that $m=n-1$. From the first we
  conclude that $n=3$, which implies that $m=2$.

With this information I can calculate the correct integral, being: $$(-\frac{2}{27}+\frac{x^2}{3})\cos(3x)+(-\frac{2x}{9}+\frac{x^3}{3})\sin(3x)+C$$
QUESTION: My question is about the last sentence. Given these conditions couldn't it also be the case that $m=4$ and $n=5$? As a matter of fact I calculated that this would indeed give the correct answer as well, but I don't fully understand why there are two options and what is going on here. Any insight would be appreciated.
 A: If you differentiate once again, you get
$$P''(x)+9P(x)=3x^2$$
thus
$$\deg(P)=2$$
and
$$Q''(x)=3x^3-9Q(x)$$
then
$$\deg(Q)=3$$
A: We know that the degree of $Q$ is one more than the degree of $P$.  Taking the derivative of $P$ only makes the degree smaller, so in the expression $P'(x)+3Q(x)$, $3Q(x)$ has higher degree than $P'(x)$.  This means that the highest power of $x$ appearing in $Q(x)$ cannot be cancelled out by $P'(x)$.  So if $P'(x)+3Q(x)=x^3$, then the $x^3$ must come from the highest-degree term of $3Q(x)$, so $Q$ has degree $3$.
It should not be a surprise that you were still able to find the same answer by saying $Q$ has terms up to degree $5$, though.  If you write $$Q(x)=ax^5+bx^4+cx^3+dx^2+ex+f,$$ this equation does NOT mean that $Q$ has degree $5$, since $a$ could be $0$.  What this equation says is that $Q$ has degree at most $5$.  So using this representation of $Q$, you can find any solution where $Q$ is a polynomial of degree at most $5$, including the case where $Q$ has degree $3$ (in that case you will just have $a=b=0$).
