Solution (source code)

= Solution

Assume the regular real <Sturm-Liouville problem>, with $p,w>0$, ordered <eigenvalues> $\lambda_0<\lambda_1<\cdots$, and real orthonormal <eigenfunctions> in the <weighted inner product>
$$
\langle u,v\rangle_w=\int_0^1uv\,w\,dx.
$$
The <Rayleigh quotient> for an admissible trial <function> is
$$
R[\widetilde y]=\frac{\int_0^1\widetilde y\mathcal L\widetilde y\,dx}{\int_0^1w\widetilde y^2\,dx}=\frac{\int_0^1[p(\widetilde y')^2+q\widetilde y^2]\,dx}{\int_0^1w\widetilde y^2\,dx}.
$$
The second expression follows by <integration by parts>. It is the quantity used in the <Rayleigh-Ritz method>.

For $\widetilde y=y_0+\sum_{n\geq1}a_ny_n$, orthonormality eliminates every cross-term in the denominator:
$$
\int_0^1w\widetilde y^2\,dx=1+\sum_{n\geq1}a_n^2.
$$
Applying $\mathcal L$ to the <eigenfunction expansion> and using the same <orthogonality> in the numerator gives
$$
\int_0^1\widetilde y\mathcal L\widetilde y\,dx=\lambda_0+\sum_{n\geq1}a_n^2\lambda_n.
$$
Hence, whenever the trial <function> has finite energy,
$$
\boxed{\widetilde\lambda_0=R[\widetilde y]=\frac{\lambda_0+\sum_{n\geq1}a_n^2\lambda_n}{1+\sum_{n\geq1}a_n^2}.}
$$
Put $S=\sum a_n^2$ and $\Delta=\sum a_n^2(\lambda_n-\lambda_0)$. The exact error and its expansion are
$$
\boxed{\widetilde\lambda_0-\lambda_0=\frac\Delta{1+S}=\Delta+O(S\Delta).}
$$
In particular, under a common small scaling $a_n=\varepsilon b_n$ with fixed finite sums $\sum b_n^2$ and $\sum b_n^2(\lambda_n-\lambda_0)$,
$$
\boxed{\widetilde\lambda_0=\lambda_0+\sum_{n\geq1}a_n^2(\lambda_n-\lambda_0)+O(\varepsilon^4).}
$$
The fourth-order remainder includes mixed products $a_n^2a_j^2$, not just individual fourth powers.

\b[Error comparison and sign.] Since $\|y_0\|_w=1$, the relative <weighted norm> error of the supplied trial <function> is
$$
\frac{\|\widetilde y-y_0\|_w}{\|y_0\|_w}=\sqrt{S}=O(\varepsilon).
$$
For $\lambda_0\ne0$, the relative <eigenvalue> error is $\Delta/(|\lambda_0|(1+S))=O(\varepsilon^2)$. Thus the <Rayleigh quotient> has a second-order error for a first-order error in the trial <eigenfunction>, provided the energy-weighted coefficient sum is controlled. Small weighted norm error alone does not control arbitrarily high-frequency contamination, because $\lambda_n$ can grow without bound. If $\lambda_0=0$, an absolute error must replace the undefined relative one.

Finally every summand of $\Delta$ is nonnegative. Thus
$$
\boxed{\widetilde\lambda_0\geq\lambda_0,}
$$
with strict inequality whenever some $a_n\ne0$. This is the upper-bound property of the <Rayleigh-Ritz variational principle> for the lowest <eigenvalue>.