For the ODE:
$$x''(t)+x(t)+2\sin t=0,\ x(0)=0,\ x'(t)=1,$$
I try to guess $$x_p(t)=A\sin t +B\cos t,$$ but the book gives me the solution $$x_p(t)=t\cos t$$ from the guess $$x_p(t)=t(A\sin t+B\cos t).$$
Why am I wrong?
For the ODE:
$$x''(t)+x(t)+2\sin t=0,\ x(0)=0,\ x'(t)=1,$$
I try to guess $$x_p(t)=A\sin t +B\cos t,$$ but the book gives me the solution $$x_p(t)=t\cos t$$ from the guess $$x_p(t)=t(A\sin t+B\cos t).$$
Why am I wrong?
On
Going by the method of undetermined coefficients, start off by finding a general solution to the problem :
$$x''(t) + x(t) = 0$$
Assume a solution will be proportional to $e^{λt}$ and by substituting in, calculate $\lambda$ :
$$λ^2e^{λt} + e^{λt}=0 \Rightarrow e^{λt}(λ^2+1)=0 \Rightarrow λ = \pm \space i$$
The roots of $\lambda$ give the following as solutions :
$$x_1(t) =c_1e^{it}, \space x_2(t) = c_2e^{-it}$$
$$x_p(t) = x_1(t) + x_2(t)$$
By applying Euler's identity and redefining the constants to a more compact form, you get :
$$x_c(t) = c_1\cos t + c_2\sin t$$
Now, the particular solution to the initial IVP is of the form :
$$x_p(t) = t(a_1\cos t + a_2\sin t)$$
Now, from the expression :
$$x''_p(t) + x_p(t) = -2\sin t$$
you can compute the values of $a_1,a_2$, by equating the coefficient of the sine and cosine terms.
Finally, you should yield that :
$$x_p(t) = t\cos t$$
So, the solution to the IVP, is :
$$\begin{cases} x(t) = c_1\cos t + c_2 \sin t + t\cos t \\ x(0)=0 \\ x'(0) = 1 \end{cases}$$
Solving this system, should yield you the final special solution of : $x(t) = t\cos t$.
On
This$$x_c(t)=C_1\sin t +C_2\cos t,$$
is a solution to your homogeneous differential equation.
In order to find $x_p(t),$ you need to multiply your $x_c(t)$ by $t$, to get $$x_p(t)=At sin t +Btcos t,$$ and find the coefficients $A$ and $B.$
Then you add $x_c(t)$ and $x_p(t)$ to find the general solution.
The reason why multiple $t$ appears in a particular solution is because you hit the resonance: $-2\sin{t}$ can be viewed as an external force with frequency 1 and your free oscillations (solution of $x''+x=0$) have frequency 1 as well.
Alternative method to guessing that you need to multiply by 1 is to use coefficient variance. It is quite a bit more laborious though. It goes as follows: solution of homogeneous problem is
$$ x_{\text{hom}}(t)=A\cos{t}+B\sin{t} $$
Suppose that heterogeneous problem solution will have a form
$$ x(t)=A(t)\cos{t}+B(t)\sin{t} $$
To find the form of $A(t)$ and $B(t)$ need to substitute it back into original equation and that's where you need to be careful (note: there exists a shortcut in this method but I always forget what needs to be assumed, so I usually go with a bruit-force): $$ x'(t)=A'\cos{t}-A\sin{t}+B'\sin{t}+B\cos{t} $$
$$ x''(t)=A''\cos{t}-2A'\sin{t}-A\cos{t}+B''\sin{t}+2B'\cos{t}-B\sin{t} $$
Notice that $-A\cos{t}-B\sin{t}=-x(t)$, thus when substitute $x''(t)$ into the equation, you get
$$ A''\cos{t}-2A'\sin{t}+B''\sin{t}+2B'\cos{t} = -2\sin{t} $$
Now the trick: second derivatives are hard, so let's assume that
$$ A''\cos{t}+B''\sin{t}=0 $$
Then
$$ -A'\sin{t}+B'\cos{t}=-\sin{t} $$
Let's introduce the notation $\alpha=A'$ and $\beta=B'$. Then above equations become
$$\begin{align}\alpha' &=-\beta'\tan{t}\\\beta &=\alpha\tan{t}-\tan{t}\end{align}$$
Differentiation of the second equation with the use of the first one yields (and, of course, using $1+\tan^2{t}=1/\cos^2{t}$):
$$ \alpha'=(1-\alpha)\tan{t} $$
This can be easily solved by separation of variables:
$$ \alpha=1+C\cos{t} $$
Using expression for $\beta$, we get
$$ \beta=C\sin{t} $$
And now everything comes together:
$$ A=\int \alpha\,dt=t+C\sin{t}+D $$
$$ B=\int\beta\,dt=-C\cos{t}+E $$
We have three constants ($C,D,E$), but $C$ will disappear as we substitute $A$ and $B$ into solution $x$:
$$ x(t)=(t+C\sin{t}+D)\cos{t}+(-C\cos{t}+E)\sin{t}=(t+D)\cos{t}+E\sin{t} $$
Finally, initial conditions:
$$ x(0) = D=0 $$
$$ x'(0) = \left[\cos{t}-t\sin{t}+E\cos{t}\right]_{t=0}=1-E=1\quad\Rightarrow\quad E=0 $$
And final solution is $x(t)=t\cos{t}$.