Solution (source code)

= Solution

Let $D=d/dx$. Repeated <integration by parts> gives the <formal adjoint> rules
$$
D^*= -D,
\qquad
(pD^2)^*=D^2p=pD^2+2p'D+p'',
\qquad
(qD)^*=-Dq=-qD-q'.
$$
Therefore
$$
L^*=D^4+pD^2+(2p'-q)D+(p''-q'+r).
$$
Equality of the coefficients of $D$ in $L$ and $L^*$ requires
$$
q=2p'-q,
$$
so $q=p'$. This also makes the zeroth-order coefficients equal because $p''-q'=0$. Hence, under boundary conditions that remove the boundary terms,
$$
\boxed{L\text{ is self-adjoint}\iff q=p'}.
$$
This is the <self-adjoint fourth-order scalar differential operator> $D^4+pD^2+p'D+r$.