Solution (source code)

= Solution

First use a homogeneous solution to meet the nonzero endpoint values:
$$
y_h(x)=\frac{a\sin(k(\pi-x))+b\sin(kx)}{\sin(k\pi)}.
$$
It satisfies $y_h''+k^2y_h=0$, $y_h(0)=a$ and $y_h(\pi)=b$. The <Green-function representation> then gives
$$
\boxed{y(x)=\frac{a\sin(k(\pi-x))+b\sin(kx)}{\sin(k\pi)}+\int_0^\pi G(x,\xi)f(\xi)\,d\xi.}
$$
Applying the differential operator to the integral gives $f(x)$ by the defining <Dirac delta> property of $G$, and that integral vanishes at the endpoints. For continuous $f$ this is a classical solution; integrable $f$ also gives the corresponding weak solution. The same nonresonant homogeneous argument as in part (a) proves uniqueness.