[Math] How to solve $y”+y=\cos x$

multivariable-calculusordinary differential equations

Solve $y''+y=\cos x$.

After first solving the homogeneous equation we know that the solution to it is $y=c_1\cos x+c_2\sin x$.

We can guess that the private solution to non-homogeneous equation will be of form: $y_p=x(A_1\cos x+A_2\sin x)$.

Then:
$$
y_p'=A_1\cos x-A_1x\sin x+A_2\sin x+A_2x\cos x\\
y_p''=-2A_1\sin x-A_1x\cos x+2A_2\cos x-A_2x\sin x
$$
If we plug these into the original equation we get:
$$
\cos x(A_1+A_2x-A_1x+2A_2)+\sin x(A_2-A_1-2A_2-A_2x)=\cos x \quad\ast
$$
We can try to solve the system:
$$
\begin{cases}
x(A_2-A_1)+A_1+2A_2=1\\
x(-A_1-A_2)+A_2-2A_1=0
\end{cases}
$$
But there're 3 unknowns in the system so I don't see how to find out the values of $A_1$ and $A_2$.

The solution says that we get $2(A_2\cos x-A_1\sin x)=\cos x$ from which is follows that $A_1=0$ and $A_2=0.5$. But how do we get to this conclusion? Is there some trick I missed?

I checked my calculations in Wolfram Alpha and they match.

Best Answer

Rewrite your last equation

$$2(A_2\cos x-A_1\sin x)=\cos x$$

as

$$2A_2 \cos x - 2 A_1 \sin x = 1 \cdot \cos x + 0 \cdot \sin x$$

From here equate coefficients of like terms on both sides: $2 A_2 = 1$ and $-2A_1 = 0$.