Q:

Solving an ODE problem.

I am having a difficulty of solving the following ODE problem.
$$f(s) = \bar f - \lambda L^2 g''(s)$$
where $\bar f = \frac{1}{L} \int_0^L f(s)\,ds$ and $s\in[0,L]$. The boundary condition is periodic $g(0)=g(1), g'(0)=g'(1)$ and the average of $f$ and $g$ is the same: $\bar f = \bar g$.

I integrate twice, use the periodic boundary condition and get the following:
$$
g ( s ) = g ( 0) + s g ^ { \prime } ( 0) - \frac { 1} { \lambda L ^ { 2} } \int _ { 0} ^ { s } ( s - \hat { s } ) ( f ( \hat { s } ) - \overline { f } ) d \hat { s } \tag{1}
$$
$$
g ^ { \prime } ( 0) = - \frac { 1} { \lambda L ^ { 3} } \int _ { 0} ^ { L } s ( f ( s ) - \overline { f } ) d s
$$
Now, I need to calculate $g(0)$ and I have a problem. What I tried is to take integrate $\int_0^L \cdot \,ds$ on the both sides of (1),
Then, I get
$$L \bar g = Lg(0)+ sLg'(0) - \int_0^L \frac { 1} { \lambda L ^ { 2} } \int _ { 0} ^ { s } ( s - \hat { s } ) ( f ( \hat { s } ) - \overline { f } ) d \hat { s }\,ds$$
Now I am in the trouble in the last term. Because the integral is now mixed together, I am confused. Is there anyone to help me?

I have the solution, but I don't know how I can derive.
$$
g ( 0) = \int _ { 0} ^ { L } f ( s ) K ( s ) d s
$$
where
$$
K ( s ) = \frac { 1} { L } \left( 1+ \frac { ( s / L ) ^ { 2} - ( s / L ) + 1/ 6} { 2\lambda } \right) ,\quad s \in [ 0,L ]
$$

A:

Define the integral function as
$$ h(s) = \int_0^s g(\hat{s}) d\hat{s} $$
Then we can integrate once more
$$ h(s) = sg(0) + \frac{s^2}{2}g'(0) - \frac{1}{2\lambda L^2}\int_0^s(s-\hat s)^2\big[f(\hat s)-\bar f\big]d\hat s $$
The average would be
\begin{align} \bar g = \frac{1}{L}h(L) &= g(0) + \frac{L}{2}g'(0) - \frac{1}{2\lambda L^3} \int_0^L (L-\hat s)^2\big[f(\hat s)-\bar f\big]d\hat s \\
&= g(0) - \frac{1}{2\lambda L^3} \int_0^L \big[L\hat s + (L-\hat s)^2\big]\big[f(\hat s)-\bar f\big]d\hat s \\
&= g(0) - \frac{1}{2\lambda L^3} \int_0^L (\hat s^2 - L\hat s)\big[f(\hat s)-\bar f\big]d\hat s
\end{align}

