Solve differential equation $y''+y=\cos^2x$
We are looking at a homogeneous equation:
$$y''+y=0$$
$$\lambda^2+1=0\Rightarrow \lambda_1=-i,\lambda_2=i\Rightarrow y_h=C_1e^{0x}\cos x+C_2e^{0x}\sin x=C_1\cos x+C_2\sin x$$
Now we find a particular solution:
$$y''+y=\cos^2x=\frac{1}{2}+\cos(2x)$$
$$y''+y=\frac{1}{2}$$
$$y_{p1}=1/2$$
$$y''+y=\cos(2x)$$
$$y_{p2}=A\sin 2x+B\cos 2x,y_{p2}''=-4A\sin 2x-4B\cos 2x$$
$$\Rightarrow A=0,B=-1/3, y_{p2}=-\frac{1}{3}\cos 2x$$
$$\Rightarrow y=y_h+y_{p1}+y_{p2}=C_1\cos x+C_2\sin x+\frac{1}{2}-\frac{1}{3}\cos 2x$$
Is this correct?
Best Answer
As @LutzL said in the comments, use:
$$\cos^2\left(x\right)=\frac{1+\cos\left(2x\right)}{2}\tag1$$
And you're correct.
Another approach, use Laplace transform:
$$\mathcal{L}_x\left[\text{y}''\left(x\right)+\text{y}\left(x\right)\right]_{\left(\text{s}\right)}=\mathcal{L}_x\left[\cos^2\left(x\right)\right]_{\left(\text{s}\right)}=\frac{1}{2}\cdot\left(\mathcal{L}_x\left[1\right]_{\left(\text{s}\right)}+\mathcal{L}_x\left[\cos\left(2x\right)\right]_{\left(\text{s}\right)}\right)\tag2$$
So, we use that:
So, we get:
$$\text{s}^2\cdot\text{Y}\left(\text{s}\right)-\text{s}\cdot\text{y}\left(0\right)-\text{y}'\left(0\right)+\text{Y}\left(\text{s}\right)=\frac{1}{2}\cdot\left(\frac{1}{\text{s}}+\frac{\text{s}}{4+\text{s}^2}\right)\tag7$$
Solving for $\text{Y}\left(\text{s}\right)$:
$$\text{Y}\left(\text{s}\right)=\frac{\frac{1}{2}\cdot\left(\frac{1}{\text{s}}+\frac{\text{s}}{4+\text{s}^2}\right)+\text{s}\cdot\text{y}\left(0\right)+\text{y}'\left(0\right)}{1+\text{s}^2}\tag8$$
Now, using inverse Laplace transform:
$$\text{y}\left(x\right)=\frac{3-\cos\left(2x\right)+\cos\left(x\right)\left(6\text{y}\left(0\right)-2\right)+6\text{y}'\left(0\right)\sin\left(x\right)}{6}\tag9$$