Solution (source code)

= Solution

Use the <drift-removing substitution for a Dirichlet Sturm-Liouville problem>, $y=e^{-x}v$. Direct differentiation gives $\mathcal Ly=e^{-x}(-v''+v)$. The homogeneous boundary conditions become $v(0)=v(\pi)=0$, so the <eigenvalues> and <eigenfunctions> are
$$
\boxed{\lambda_n=n^2+1,\qquad y_n=e^{-x}\sin(nx),\quad n=1,2,\ldots.}
$$
The self-adjoint weighted form is
$$
\mathcal Ly=-e^{-2x}(e^{2x}y')',\qquad
-(e^{2x}y')'=\lambda e^{2x}y.
$$
Thus the weight and leading coefficient are both $e^{2x}$. The <orthogonality of Sturm-Liouville eigenfunctions> reads
$$
\int_0^\pi e^{2x}y_ny_m\,dx=\frac\pi2\delta_{nm}.
$$
After multiplying the forcing equation by $e^x$, it becomes $-v''+v=x$. Expanding $x$ in the sine series of part (i) and dividing by $n^2+1$ gives
$$
\boxed{y(x)=2e^{-x}\sum_{n=1}^\infty
\frac{(-1)^{n+1}\sin(nx)}{n(n^2+1)}.}
$$
Every term satisfies the endpoint conditions. As a check, solving the transformed ODE directly gives $v=x-\pi\sinh x/\sinh\pi$, which has the same coefficients and forcing.