Method of Undetermined Coefficients/Sine and Cosine

Proof Technique
Consider the nonhomogeneous linear second order ODE with constant coefficients:
 * $(1): \quad y'' + p y' + q y = R \left({x}\right)$

Let $R \left({x}\right)$ be a linear combination of sine and cosine:
 * $R \left({x}\right) = \alpha \sin b x + \beta \cos b x$

The Method of Undetermined Coefficients can be used to solve $(1)$ in the following manner.

Method and Proof
Let $y_g \left({x}\right)$ be the general solution to:
 * $y'' + p y' + q y = 0$

From Solution of Constant Coefficient Homogeneous LSOODE, $y_g \left({x}\right)$ can be found systematically.

Let $y_p \left({x}\right)$ be a particular solution to $(1)$.

Then from General Solution of Linear 2nd Order ODE from Homogeneous 2nd Order ODE and Particular Solution:
 * $y_g \left({x}\right) + y_p \left({x}\right)$

is the general solution to $(1)$.

It remains to find $y_p \left({x}\right)$.

Let $R \left({x}\right) = \alpha \sin b x + \beta \cos b x$.

Consider the auxiliary equation to $(1)$:
 * $(2): \quad m^2 + p m + q = 0$

There are two cases to consider.


 * $i b$ is not a root of $(2)$

Assume that there is a particular solution to $(1)$ of the form:
 * $y_p = A \sin b x + B \cos b x$

We have:

Inserting into $(1)$:

Hence $A$ and $B$ can be expressed in terms of $\alpha$ and $\beta$:

Hence:
 * $y_p = \dfrac{\alpha \left({q - b^2}\right) + \beta b p} {\left({q - b^2}\right)^2 + b^2 p^2} \sin b x + \dfrac{\beta \left({q - b^2}\right) - \alpha b p} {\left({q - b^2}\right)^2 + b^2 b^2} \cos b x$


 * $i b$ is a root of $(2)$

Suppose $(1)$ is in the form:
 * $(3): \quad y'' + b^2 y = \alpha \sin b x + \beta \cos b x$

From Second Order ODE: $y'' + k^2 y = 0$ the general solution to $(2)$ is:
 * $y = C_1 \sin b x + C_2 \cos b x$

and it can be seen that an expression of the form $A \sin b x + B \cos b x$ is already a particular solution of $(2)$.

Thus $\left({q - b^2}\right)^2 + b^2 p^2 = 0$.

Thus $\dfrac {\alpha \left({q - b^2}\right) + \beta b p} {\left({q - b^2}\right)^2 + b^2 p^2}$ and $\dfrac {\beta \left({q - b^2}\right) - \alpha b p} {\left({q - b^2}\right)^2 + b^2 p^2}$ are undefined.

So, assume that there is a particular solution to $(1)$ of the form:
 * $y_p = x \left({A \sin b x + B \cos b x}\right)$

We have:

Inserting into $(3)$:

Hence $A$ and $B$ can be expressed in terms of $\alpha$ and $\beta$:

Hence:
 * $y_p = \dfrac {\beta x \sin b x} {2 b} - \dfrac {\alpha x \cos b x} {2 b}$