When is a test function multiplied by "$t$" for inhomogeneous ODEs? I was wondering how we can tell that we need to multiply our arbitrary function by $t$ when we're solving an inhomogeneous ODE?
For example, I had the following equation to solve$$\ddot x(t) +x(t) = 4\cos(t) + \cos(2t).$$The solution showed that I needed to multiply the test function associated with $4\cos(t)$ by $t$. That is, if the particular solution is defined as $$x_p(t) = x_p^{(1)}(t) + x_p^{(2)}(t)$$then I had that $$x_p^{(1)}(t) = t(c_1\cdot \cos(t) + c_2\cdot \sin(t))$$and $$x_p^{(2)}(t) = c_3\cdot \cos(2t) + c_4\cdot \sin(2t).$$Is it because the $\cos(t)$ term is multiplied by a constant? So it could be the result of the chain rule [e.g. $\frac{d}{dt}(4t\cos(t))$]?
 A: This is because you're using the undetermined coefficient, so since $\ddot{x}+x=4\cos(t)$ so you suppose the particular solution is given by $x_{p}^{(1)}=t^{s}(A\cos t+B\sin t)$ for some $s$ what you need to find. In this case $s=1$ work. Similar case for $\ddot{x}+x=\cos 2t$ so you suppose the particular solution is given by $x_{p}^{(2)}=t^{s}(C\cos 2t+D\sin 2t)$ for some $s$ which you need to find. In this case $s=0$ work.
The method of undetermined coefficients is an educated guess or an educated intuition of the form that a particular solution will take. There are many forms or rules already established for cases like the one I just mentioned.
In your case the complementary solution is given by
$$x_{c}=c_{1}\cos t+c_{2}\sin t$$ with $c_{1}$ and $c_{2}$ arbitrary constants.
And the particular solution is given by
$$x_{p}=-\frac{1}{3}\cos 2t+2t\sin t$$
by superposition principle.
Therefore the general solution for the ODE is given by
$$x=x_{c}+x_{p}$$
Is to say,
$$\boxed{x=c_{1}\cos t+c_{2}\sin t-\frac{1}{3}\cos 2t+2t\sin t}$$
There is also the parameter variation method that has closed formulas to find the particular solution. If you need more detail, I can add more information in my post.
