Eigenvalues and eigenvectors of tridiagonal symmetric Toeplitz matrices (interactive visualization)

This program illustrates the eigenvalues and eigenvectores of Toeplitz matrices with entries −1, 2, −1.
The corresponding formulas are well known.

Choose the order n of the matrix:

n = 8

Next picture shows the graph of the generating function g(x) = 4 sin(x / 2)^{2}.
The ordinates of the yellow points are the eigenvalues of the corresponding n×n matrix.

The eigenvalues λ_{n,1}, …, λ_{n,n} are numbered in the ascending order.
For each j = 1, …, n, the eigenvalue λ_{n,j} is computed as
g(jπ / (n + 1)).

Next figure shows the components of an eigenvectorv_{n,j} associated to λ_{n,j}.
Recall that n = 8 (the value of n can be changed above).
Choose the index j of the eigenvalue/eigenvector pair:

j = 1

Next picture shows a family portrait of the eigenvectors, i.e. the matrix of the Discrete Sine Transform.
The color of the cell (p, j) corresponds to the value of the component p of a normalized eigenvector associated to λ_{n,j}.
For example, the column corresponds to the eigenvector shown above (after normalization).