Uniqueness of weight function. Let $L=p(x)\frac{d^2}{dx^2}+q(x)\frac{d}{dx}+r(x).$  Where L stands for differential operator.  Now inner product defined $(f,g)=\int_a^bf(x)g(x)w(x)dx$. Where $w(x)$ is a weight function.  Now $L$ is symmetric with respect to weight function if $(Lu,v)=(u,Lv)$.
Need to prove if $L=p(x)\frac{d^2}{dx^2}+q(x)\frac{d}{dx}+r(x)$ then there is a weight function, and it is unique up to a constant, such that L is symmetric with respect to w.
 A: Well, first you need to do some algebra: Given that $w > 0$,
\begin{align}
\langle L u, v \rangle &= \int_a^b \left(p u'' + q u' + r u \right) v w dx \\
&= \int_a^b \left((p w v)'' - (q w v)' + r w v \right) u dx + \mbox{BT}\\
&= \int_a^b \left( p v'' + \left[\frac{2(p w)'}{w}- q\right]v' + \left[\frac{(pw)'' -(qw)'}{w} +r \right]v\right) u w dx + \mbox{BT} \\ \\
&= \langle u, L^\dagger v \rangle + \mbox{BT}
\end{align}
We need the boundary terms to vanish, which has to do with the original boundary conditions for $L$.
For $L$ to be symmetric with respect to $w$, $L = L^\dagger$. Hence
\begin{align}
\frac{2(p w)'}{w}- q &= q\\
\frac{(pw)'' -(qw)'}{w} +r &=r
\end{align}
The second equation is redundant of the first one, and the condition becomes
$$
(p w)' - q w = 0.
$$
This means that $w$ must solve
$$
p w' + (p' - q) w = 0.
$$
If $p' - q = 0$, then $w = c$ where $c$ is a constant is a solution (we already knew that). If $p' - q \neq 0$,
$$
\frac{w'}{w} = \frac{p' - q}{p} \qquad \Longrightarrow \qquad w = e^{\int  \frac{p' - q}{p} dx}
$$
which is positive and unique up to a constant of integration.
Note that this result is valid only in a vicinity of $x$ where $p(x) \neq 0$. The singular points must be treated with care.
