Solution (source code)

= Solution

Let $\theta_k=k\pi h=k\pi/(m+1)$ and define $q^{(k)}_j=\sin(j\theta_k)$. The artificial boundary values are $q^{(k)}_0=q^{(k)}_{m+1}=0$. For the <symmetric tridiagonal Toeplitz matrix> $H=[\beta,\alpha,\beta]$, the <sine addition formula> gives
$$
(Hq^{(k)})_j
=\alpha\sin(j\theta_k)
+\beta\bigl[\sin((j-1)\theta_k)+\sin((j+1)\theta_k)\bigr]
=\bigl(\alpha+2\beta\cos\theta_k\bigr)q^{(k)}_j.
$$
Thus all such matrices have the same <discrete sine transform> eigenvectors, with eigenvalues
$$
\boxed{\lambda_k=\alpha+2\beta\cos(k\pi h),
\qquad k=1,\ldots,m.}
$$
The sine vectors are mutually <orthogonal vectors> and nonzero, so the matrix $Q=(\sin(ij\pi h))_{i,j=1}^m$ is invertible. If $D=\operatorname{diag}(\lambda_1,\ldots,\lambda_m)$, then $HQ=QD$ and therefore
$$
\boxed{H=QDQ^{-1}.}
$$