I want to construct the following matrix $M$ of dimension $(N+1)\times(N+1)$ with the following rule (for arbitrary N). Below, in the subscript, as usual, the 1st index gives the row and the second one the column. The subscript indices go from 0 to $N$.
\begin{equation} M_{00}=\frac{2N^2+1}{6},\, M_{NN}=-\frac{2N^2+1}{6}\\ M_{jj}=-\frac{x_j}{2(1-x_j^2)}\quad\mbox{for}\quad j=1\dots N-1\\ M_{ij}=\frac{c_i}{c_j}\frac{(-1)^{i+j}}{(x_i-x_j)}\quad\mbox{for}\quad i\neq j,\, i,j=0\dots N\\ \end{equation}
Above, $c_i=2$ for $i=0$ or $N$, and 1 otherwise. The $x_j$'s ($j=0\dots N$) are defined as $x_j=\cos(j\pi/N)$.
The above rule should unambiguously tell us all the matrix entries, but how to implement it in Mathematica is beyond me. A nice, understandable program will be very helpful. Thanks a lot in advance!
SparseArray
and rules, then converting theSparseArray
object to aNormal
matrix. $\endgroup$ – MarcoB Jan 29 '16 at 16:24