Solve ODE with cosine involved

ordinary differential equations

I sought for this really long in the internet but didn't happen to find a general solution.
So here is the equation:

$y' = y + x\,\cos(2\,x)$

I know that for the particular solution $y_p$ following assumption is made:

$y_p = (a_0+a_1\,x)\,\sin(2\,x)+(b_0+b_1\,x)\,\cos(2\,x)$

so that

$\begin{align}
{y_p}' &= a_1\,\sin(2\,x)+(a_0+a_1\,x)\,2\,\cos(2\,x)+ b_1\,\cos(2\,x)-(b_0+b_1\,x)\,2\,\sin(2\,x)
\\ &=y + x\,\cos(2\,x) = {y_p}'
\end{align}$

But I don't know at all how to determine $a_1, a_0, b_1, b_0$

I could also just solve $y = C\,e^{x} +e^{x}\,\int{\frac{\cos(2\,x)}{e^x}}\mathrm{d}x$ thanks to another answer here, but how to do it generally?

Best Answer

Grouping by $sin(2x)$ gives the equation:

$$a_1 - 2b_0 = a_0$$

Grouping by $x sin(2x)$:

$$-2b_1 = a_1$$

Grouping by $cos(2x)$:

$$2a_0 + b_1 = b_0$$

Grouping by $x cos(2x)$: $$2a_1 = b_1 + 1$$

Solve and you get $b_1 = -1/5$, $a_1 = 2/5$, $a_0 = 4/25$, $b_0 = 3/25$.

Related Question