Finding the general solution of the differential equation $\,\,y''+y=f(x)$ I am stuck with the following problem:  

I have to show that the general solution of the differential equation $$y''+y=f(x)\,\, ,x \in (-\infty,\infty)$$, where $f$ is continuous real valued function on  $(-\infty,\infty)$ is $$y(x)=A \cos x+B \sin x + \displaystyle \int_{0}^{x} f(t) \sin (x-t) dt\,\, $$ where $A,B$ are constants.  

C.F. part of the reduced differential equation $y''+y=0$ is : $A \cos x+B \sin x$. But I am having trouble to get the P.I.(particular integral) which can be obtained by solving $$\frac {1}{D^2+1} f(x)$$,where $D \equiv \frac {d}{dx}$. This is where I am stuck.
Am I going in the right direction? Can someone help?
Thanks and regards to all.
 A: Recalling the Laplace transform of a function $f$

$$ F(s) = \int_{0}^{\infty}f(x)\,e^{-sx}dx $$

Taking the Laplace transform of the ode
$$ y''+y=f(x) $$
yields
$$ s^2Y(s)+Y(s)-s \,y(0)-y'(0)=F(s) $$
$$ \implies Y(s)=\frac{y'(0)}{s^2+1}+\frac{y(0)s}{s^2+1}+\frac{F(s)}{s^2+1} $$
Now, we take the inverse Laplace transform of the above equation to get 
$$ y(x) = A\sin(x)+B\cos(x)+ \int_{0}^{x} \sin(x-t)f(t)dt. $$
Notes:
1) $$ \mathcal{L}\,y^{(n)}(x) = s^n F(s) - \sum_{k=1}^{n} s^{k-1} f^{(n-k)}(0). $$ 
2) $$\mathcal{L} (\sin(x))=\frac{1}{s^2+1},\quad \mathcal{L} (\cos(x))=\frac{s}{s^2+1}$$
3) $$ \mathcal{L}^{-1}(F(s)G(s))=(f*g)(x).  $$
A: Observe that the solutions to the corresponding homogenous equation are sin x and cos x . Using variation of parameters will give you the required result. Wronskian of $\cos x $ and $\sin x$ is therefore
$$
\begin{align}
y_p&= \cos x\int_{0}^x f(t) (-\sin t) dt+\sin x\int_{0}^x f(t)\cos t dt  \\
y_p&= \int_{0}^x f(t)[\sin x\cos t-\cos x\sin t]dt \\
y_p&=\int_{0}^x f(t)\sin (x-t) dt\\
\end{align}
$$
A: Notice that $y''(x)+y(x)=y''(x)-[i-(-i)]y'(x)+[i\cdot(-i)]y(x)=y''(x)-iy'(x)+i[y'(x)-iy(x)]=(y'-iy)'(x)+i(y'-iy)(x).$ Let $z=y'-iy,$ hence $z'+iz=f.$ This is equivalent to $\exp(ix)z'(x)+i\exp(ix)z(x)=\exp(ix)f(x)=[\exp^i\cdot{z}]'(x).$ Integrating on $[0,t]$ results in $$\exp(it)z(t)-z(0)=\int_0^t\exp(ix)f(x)\,\mathrm{d}x,$$ implying $$z(t)=z(0)\exp(-it)+\exp(-it)\int_0^t\exp(ix)f(x)\,\mathrm{d}x=y(t)'-iy(t).$$ This is equivalent to $$\exp(-it)y'(t)-i\exp(-it)y(t)=[\exp^{-i}\cdot{y}]'(t)$$ $$=[y'(0)-iy(0)]\exp(-2it)+\exp(-2it)\int_0^t\exp(ix)f(x)\,\mathrm{d}x.$$ Integrating on $[0,s]$ results in $$\exp(-is)y(s)-y(0)$$ $$=\frac{i}2[y'(0)-iy(0)][\exp(-2is)-1]+\int_0^s\exp(-2it)\int_0^t\exp(ix)f(x)\,\mathrm{d}x\,\mathrm{d}t$$ $$=\frac{i}2[y'(0)-iy(0)][\exp(-2is)-1]+\frac{i}2\exp(-2is)\int_0^s\exp(ix)f(x)\,\mathrm{d}x-\frac{i}2\int_0^s\exp(-ix)f(x)\,\mathrm{d}x,$$ which is equivalent to $$y(s)-y(0)\exp(is)=\frac{i}2[y'(0)-iy(0)][\exp(-is)-\exp(is)]+\frac{i}2\exp(-is)\int_0^s\exp(ix)f(x)\,\mathrm{d}x-\frac{i}2\exp(is)\int_0^s\exp(-ix)f(x)\,\mathrm{d}x$$ $$=[y'(0)-iy(0)]\sin(s)+\frac1{2i}\int_0^s(\exp[i(s-x)]-\exp[-i(s-x)]f(x)\,\mathrm{d}x$$ $$=y'(0)\sin(s)-iy(0)\sin(s)+\int_0^s\sin(s-x)f(x)\,\mathrm{d}x=y(s)-y(0)\cos(s)-iy(0)\sin(s).$$ Therefore, $$y(s)=y(0)\cos(s)+y'(0)\sin(s)+\int_0^s\sin(s-x)f(x)\,\mathrm{d}x.$$
