I am trying to discretize the differential operator $\frac{d^2}{dx^2}$ acting on $S^1 = [0,1]$ using finitely many points around a circle at $0, \frac{1}{N}, \frac{2}{N}, \dots, \frac{N-1}{N}$.
Here is the matrix for $N=5$:
$$\left[ \begin{array}{cc} -2 & 1 & 0 & 0 & 1 \\ 1 & -2 & 1 & 0 & 0 \\ 0 & 1 & -2 & 1 & 0 \\ 0 & 0 & 1 & -2 & 1 \\\ 1 &0 & 0 & 1 & -2\end{array} \right]$$
If we solved the equation $\frac{d^2 f}{dx^2} = \lambda f$ we should get $f(x) = e^{\lambda x}$ with $\lambda = 2\pi k$ and $k^2 \in \mathbb{Z}$.
When I implemented this in numpy, the reascaling seems all wrong. Can someone explain a little bit of the theory behind this?
N = 100
A = np.zeros((N,N))
d = np.arange(N)
A[d,d] = -2
A[d,(d+1)%N]=1
A[d,(d-1)%N]=1
A
The resulting matrix is like I said. Here $N=100$.
array([[-2., 1., 0., ..., 0., 0., 1.],
[ 1., -2., 1., ..., 0., 0., 0.],
[ 0., 1., -2., ..., 0., 0., 0.],
...,
[ 0., 0., 0., ..., -2., 1., 0.],
[ 0., 0., 0., ..., 1., -2., 1.],
[ 1., 0., 0., ..., 0., 1., -2.]])
I came up with this adhoc scaling for the eigenvalues of $-A$ dividing them by $(2 \pi N)^2$.
L = np.linalg.eig(-A)[0]/(2*np.pi)**2*N**2
L = np.round(L)
np.sort(L).astype(int)
The result looks pretty close. I get the sequence of perfect squares. Does that mean $\frac{1}{2\pi N}A$ is the correct rescaling?
array([ 0, 1, 1, 4, 4, 9, 9, 16, 16, 25, 25,
36, 36, 48, 48, 63, 63, 79, 79, 97, 97, 116,
116, 137, 137, 160, 160, 184, 184, 209, 209, 235, 235,
263, 263, 291, 291, 320, 320, 350, 350, 381, 381, 412,
412, 443, 443, 475, 475, 507, 507, 538, 538, 570, 570,
602, 602, 633, 633, 663, 663, 693, 693, 722, 722, 751,
751, 778, 778, 804, 804, 830, 830, 853, 853, 876, 876,
897, 897, 916, 916, 934, 934, 951, 951, 965, 965, 978,
978, 988, 988, 997, 997, 1004, 1004, 1009, 1009, 1012, 1012,
1013])
L = np.linalg.eig(-A)[0]/(2*np.pi)**2*N**2
does not match up with dividing by $(2 \pi N)^2$. $\endgroup$L = np.linalg.eig(-A)[0]/(2*np.pi*N)**2
$\endgroup$