Finite difference approximation of $u''(x)+u(x)=0, u(0)=1, u(\pi)=-1$.
For the approximation for this, do I get:
$$\frac{1}{h^2}(U_{j-1}-2U_j+U_{j+1})+U_j$$ $$=\frac{1}{h^2}(U_{j-1}+(h^2-2)U_j+U_{j+1})$$
Then the matrix A would have $h^2-2$ on the main diagonal with ones on the diagonal above and below?

What I am confused about, is that I am trying to show that the eigenvalues go to 0 as h goes to 0 of the ODE, but this doesn't hold for this matrix, so I feel like I made a mistake in the derivation of the matrix.
Thanks.
If you let $h^2-2-\lambda=x$, then the eigenvalue equation becomes $P_n(x)=0$, where $P_n(x)$ is the determinant of the $n\times n$ matrix with $x$ on the main diagonal and $1$ on the adjacent diagonals. For example, $$P_4(x)=\det\begin{bmatrix}x&1&0&0\\ 1&x&1&0\\ 0&1&x&1\\ 0&0&1&x\end{bmatrix}$$ If we expand the determinant along the first column we get the difference equation $P_n(x)=xP_{n-1}(x)-P_{n-2}(x)$ with initial conditions $P_1(x)=x$ and $P_2(x)=x^2-1$. Let $P_n(x)=Cr^n$. Then $r^2-xr+1=0$ or $$r=\frac{x\pm\sqrt{x^2-4}}2$$ So $$P_n(x)=C_1\left(\frac{x+\sqrt{x^2-4}}2\right)^n+C_2\left(\frac{x-\sqrt{x^2-4}}2\right)^n$$ Applying initial conditions, $$P_1(x)=x=C_1\left(\frac{x+\sqrt{x^2-4}}2\right)+C_2\left(\frac{x-\sqrt{x^2-4}}2\right)$$ $$P_2(x)=x^2-1=C_1\left(\frac{x^2-2+x\sqrt{x^2-4}}2\right)+C_2\left(\frac{x^2-2-x\sqrt{x^2-4}}2\right)$$ $$xP_1(x)-P_2(x)=1=C_1+C_2$$ $$\frac{\sqrt{x^2-4}}2\left(C_1-C_2\right)+\frac x2\left(C_1+C_2\right)=\frac{\sqrt{x^2-4}}2\left(C_1-C_2\right)+\frac x2=P_1(x)=x$$ $$C_1-C_2=\frac x{\sqrt{x^2-4}}$$ Adding and subtracting we arrive at $$C_1=\frac{x+\sqrt{x^2-4}}{2\sqrt{x^2-4}}\text{; }C_2=-\frac{x-\sqrt{x^2-4}}{2\sqrt{x^2-4}}$$ So $$P_n(x)=\frac1{\sqrt{x^2-4}}\left[\left(\frac{x+\sqrt{x^2-4}}2\right)^{n+1}-\left(\frac{x-\sqrt{x^2-4}}2\right)^{n+1}\right]$$ All the roots are within $-2<x<2$, so $$\left|\frac{x+\sqrt{x^2-4}}2\right|=\left|\frac{x+i\sqrt{4-x^2}}2\right|=\sqrt{\frac{x^2+4-x^2}4}=1$$ So if $P_n(x)=0$ then $$\left(\frac{x+\sqrt{x^2-4}}2\right)^{2n+2}=1=e^{2\pi ik}$$ $$\frac{x+\sqrt{x^2-4}}2=\exp\left(\frac{\pi ik}{n+1}\right)=\cos\left(\frac{\pi k}{n+1}\right)+i\sin\left(\frac{\pi k}{n+1}\right)$$ Taking real parts, $$x=2\cos\left(\frac{\pi k}{n+1}\right)=\frac{\pi^2}{(n+1)^2}-2-\lambda$$ So $$\lambda=\frac{\pi^2}{(n+1)^2}-2\left(1+\cos\left(\frac{\pi k}{n+1}\right)\right)=\frac{\pi^2}{(n+1)^2}-4\cos^2\left(\frac{\pi k}{2(n+1)}\right)$$ The smallest eigenvalue is when $k=n$ and is about $\frac{\pi^4}{12(n+1)^4}$.
But what do you need the eigenvalues for? The difference equation for $U_j$ is easy enough to solve: $$U_j=A\cos\left(j\theta-\delta\right)$$ Where $$\theta=\text{atan2}\left(h\sqrt{4-h^2},2-h^2\right)$$ and $h=\frac{\pi}{n+1}$, $\delta=(n+1)\theta/2-\pi/2$, and $A=\sec\delta$