Solution (source code)

= Solution

The <exponential substitution removing a constant first derivative>, $y=e^xu$, reduces the equation to $u''+\beta^2u=1+\cos x$. For $\beta\ne0$ and $\beta^2\ne1$, solve the homogeneous harmonic equation and use a constant plus a cosine for the particular solution:
$$
\boxed{y=e^x\left[A\cos(\beta x)+B\sin(\beta x)+\frac1{\beta^2}+\frac{\cos x}{\beta^2-1}\right].}
$$
There is a further exceptional case inside the printed condition $\beta^2\ne1$: \b[$\beta=0$ must be treated separately]. It gives $u''=1+\cos x$, hence
$$
\boxed{y=e^x\left[A+Bx+\frac{x^2}{2}-\cos x\right],\qquad\beta=0.}
$$
This retains the constant forcing's <resonance> with the zero-<frequency> homogeneous equation. Substitution verifies both branches.