ODE $f''''(x)+f(x) = \cos{x} - \left( \sin{x} \right)^2$ with boundary conditions $f(0)=f(\pi); \quad \quad f'(0)=f'(\pi)$ Today I've attended a Mathematical Methods for Physicist exam and I've found an ordinary differential equation that I could not solve.
The exercise asked to find a solution to the equation
$$ f''''(x)+f(x) = \cos{x} - \left( \sin{x} \right)^2$$
with boundary conditions
$$ f(0)=f(\pi); \quad \quad f'(0)=f'(\pi)$$
First of all, I've written $\sin^2{x}$ = $\frac{1}{2}-\frac{1}{2} \cos{2x}$; then I've tried to expand $f(x)$ in Fourier series between $0$ and $\pi$:
$$f(x)=\sum_{n=0}^{\infty} \left( a_n \cos{nx} + b_n \sin{nx}\right)$$
Then I've imposed the first boundary condition. Since $f(0)$ is just the sum of $a_n$, and $f(\pi)$ is the sum of $a_n (-1)^n$, the condition is fulfilled if only the even terms are non-zero; hence:
$$f(x) = \sum_{n=0}^{\infty} \left( a_{2n} \cos{2nx} + b_n \sin{nx} \right)$$
$$f'(x) = \sum_{n=0}^{\infty} \left( n b_n \cos{nx} - 2n \; a_{2n} \sin{2nx} \right)$$
At this point imposing the second boundary condition gave me a result specular to the first one (only even terms for $b_n$):
$$f(x) = \sum_{n=0}^{\infty} \left( a_{2n} \cos{2nx} + b_{2n} \sin{2nx} \right)$$
Then I've finally substituted the expanded form of $f(x)$ into the differential equation in order to find the coefficients:
$$f''''(x)+f(x) = \sum_{n=0}^{\infty} \left( a_{2n} (16n^4+1) \cos{2nx}  +  b_{2n} (16n^4+1) \sin{2nx} \right) = \cos{x}-\frac{1}{2}+\frac{1}{2}\cos{2x}$$
And now I'm stuck... I can find the coefficients for $n=0$ and $n=1$, but I don't know what to do with the $\cos{x}$ term.
Thanks in advance for any help or suggestion you may give,
Lorenzo
 A: $$f''''(x)+f(x) = \cos{x} - \left( \sin{x} \right)^2$$
Solve the homogeneous equation first:
$$f''''(x)+f(x) = 0$$
the characteristic polynomial is
$$r^4+1=0$$
Solve for $r$ then the solution is
$$y_h=\sum_{i=1}^4c_ie^{r_ix}$$

For the particular solution
$$f''''(x)+f(x)  = \cos{x}-\frac{1}{2}+\frac{1}{2}\cos{2x}$$
Try
$$y_p=A+B\cos x +C \cos(2x)$$
You find that
$$A=-\dfrac 12$$
$$B\cos x+B \cos x=  \cos x \implies B=\dfrac 12$$
$$16C\cos (2x)+C \cos (2x)= \dfrac 12 \cos (2x) $$
$$\implies C=\dfrac 1 {34}$$
So thatthe particular solution is:
$$y_p=-\dfrac 12 + \dfrac 12 \cos x +\dfrac 1 {34}\cos(2x)$$
A: Trying a solution of the form $e^{\lambda x}$ for the homogeneous problem, we have the characteristic equation (or auxiliary equation) $\lambda^{4}+1=0,$ which has the roots $\lambda=e^{\frac{i\pi}{4}(1+2k)}$ for $k=0, 1,2 $ and $3.$
For instance when $k=0$ we have $e^{x(\cos(\frac{\pi}{4})+i\sin(\frac{\pi}{4}))}=e^{\frac{x}{\sqrt{2}}}(\cos(\frac{x}{\sqrt{2}})+i\sin(\frac{x}{\sqrt{2}})).$
So the homogenous solution is $$y_{h}(x)=c_1e^{-\frac{x}{\sqrt{2}}}\sin(\frac{x}{\sqrt{2}})+c_2e^{\frac{x}{\sqrt{2}}}\sin(\frac{x}{\sqrt{2}})+c_3e^{\frac{x}{\sqrt{2}}}\cos(\frac{x}{\sqrt{2}})+c_4e^{-\frac{x}{\sqrt{2}}}\cos(\frac{x}{\sqrt{2}}).$$
Now for the homogenous problem we try a particular solution of the form $$y_p(x)=A\cos(x)+B\sin(x)+C\cos(2x)+D\sin(2x)+E$$ since the RHS is equivalent to $\frac{1}{2}(2\cos(x)+\cos(2x)-1).$ Then substituting into the ODE we find that
$$A=\frac{1}{2}\space\space\space\space B=-\frac{1}{2}\space\space\space\space C=\frac{1}{130}\space\space\space\space D=-\frac{4}{65}\space\space\space\space \text{and}\space\space\space\space E=-\frac{1}{2} \space\space\space.$$
Now that you have $f(x)=y_{h}(x)+y_{p}(x)$ you use the boundary conditions $f(0)=f(\pi)$ and $f'(0)=f'(\pi)$ to find $c_1,c_2,c_3$ and $c_4.$
