Theorem: Linear Second Order ODE/y'' + k^2 y = sine b x

The second order ODE:
:$(1): \quad y'' + k^2 y = \sin b x$
has the general solution:
:$y = \begin{cases} C_1 \sin k x + C_2 \cos k x + \dfrac {\sin b x} {k^2 - b^2} & : b \ne k \\
C_1 \sin k x + C_2 \cos k x - \dfrac {x \cos k x} {2 k} & : b = k 
\end{cases}$

Proof:
It can be seen that $(1)$ is a nonhomogeneous linear second order ODE with constant coefficients in the form:
:$y'' + p y' + q y = \map R x$
where:
:$p = 0$
:$q = k^2$
:$\map R x = \sin b x$
First we establish the solution of the corresponding constant coefficient homogeneous linear second order ODE:
:$(2): \quad y'' + k^2 y = 0$
From Linear Second Order ODE: $y'' + k^2y = 0$, this has the general solution:
:$y_g = C_1 \sin k x + C_2 \cos k x$
We have that:
:$\map R x = \sin b x$
There are two cases to address:
:$b = k$
:$b \ne k$
First suppose that $b = k$.
It is noted that $\sin b x = \sin k x$ is a particular solution of $(2)$.
So from the Method of Undetermined Coefficients for Sine and Cosine:
:$y_p = A x \sin k x + B x \cos k x$
where $A$ and $B$ are to be determined.
Hence:
{{begin-eqn}}
{{eqn | l = y_p
      | r = A x \sin k x + B x \cos k x
      | c = 
}}
{{eqn | ll= \leadsto
      | l = {y_p}'
      | r = A k x \cos k x - B k x \sin k x + A \sin k x + B \cos k x
      | c = Derivative of Sine Function, Derivative of Cosine Function, Product Rule for Derivatives
}}
{{eqn | ll= \leadsto
      | l = {y_p}''
      | r = -A k^2 x \sin k x - B k^2 x \cos k x + A k \cos k x - B k \sin k x + A k \cos k x - B k \sin k x
      | c = Derivative of Sine Function, Derivative of Cosine Function, Product Rule for Derivatives
}}
{{eqn | r = -A k^2 x \sin k x - B k^2 x \cos k x + 2 A k \cos k x - 2 B k \sin k x
      | c = 
}}
{{end-eqn}}
Substituting into $(1)$:
{{begin-eqn}}
{{eqn | l = -A k^2 x \sin k x - B k^2 x \cos k x + 2 A k \cos k x - 2 B k \sin k x + k^2 \paren {A x \sin k x + B x \cos k x}
      | r = \sin k x
      | c = 
}}
{{eqn | ll= \leadsto
      | l = A \paren {k^2 - k^2} x \sin k x - 2 B k \sin k x
      | r = \sin k x
      | c = equating coefficients
}}
{{eqn | l = B \paren {k^2 - k^2} x \cos k x + 2 A k \cos k x
      | r = 0
      | c = 
}}
{{eqn | ll= \leadsto
      | l = - 2 B k
      | r = 1
      | c = 
}}
{{eqn | l = 2 A k
      | r = 0
      | c = 
}}
{{eqn | ll= \leadsto
      | l = A
      | r = 0
      | c = 
}}
{{eqn | ll= \leadsto
      | l = B
      | r = -\frac 1 {2 k}
      | c = 
}}
{{end-eqn}}
So from General Solution of Linear 2nd Order ODE from Homogeneous 2nd Order ODE and Particular Solution:
:$y = y_g + y_p = C_1 \sin k x + C_2 \cos k x - \dfrac {x \cos k x} {2 k}$
{{qed|lemma}}
Now suppose that $b \ne k$.
It is noted that $\sin b x$ is not a particular solution of $(2)$.
So from the Method of Undetermined Coefficients for Sine and Cosine:
:$y_p = A \sin b x + B \cos b x$
where $A$ and $B$ are to be determined.
Hence:
{{begin-eqn}}
{{eqn | l = y_p
      | r = A \sin b x + B \cos b x
      | c = 
}}
{{eqn | ll= \leadsto
      | l = {y_p}'
      | r = A b \cos b x - B b \sin b x
      | c = Derivative of Sine Function, Derivative of Cosine Function
}}
{{eqn | ll= \leadsto
      | l = {y_p}''
      | r = -A b^2 \sin b x - B b^2 \cos b x
      | c = Derivative of Sine Function, Derivative of Cosine Function
}}
{{end-eqn}}
Substituting into $(1)$:
{{begin-eqn}}
{{eqn | l = -A b^2 \sin b x - B b^2 \cos b x + k \paren {A \sin b x + B \cos b x}
      | r = \sin b x
      | c = 
}}
{{eqn | ll= \leadsto
      | l = A \paren {k^2 - b^2} \sin b x
      | r = \sin b x
      | c = equating coefficients
}}
{{eqn | l = B \paren {k^2 - b^2} \cos b x
      | r = 0
      | c = 
}}
{{eqn | ll= \leadsto
      | l = A
      | r = 0
      | c = 
}}
{{eqn | l = B
      | r = \frac 1 {k^2 - b^2}
      | c = 
}}
{{end-eqn}}
So from General Solution of Linear 2nd Order ODE from Homogeneous 2nd Order ODE and Particular Solution:
:$y = y_g + y_p = C_1 \sin k x + C_2 \cos k x + \dfrac {\sin b x} {k^2 - b^2}$
{{qed}}