Without SparseArray
:
n = 10;
Total[
{DiagonalMatrix[Array[-1 &, n - 1], -1],
DiagonalMatrix[Array[2 &, n]],
DiagonalMatrix[Array[-1 &, n - 1], 1]}
]
Or strictly using Array
:
Array[Which[#1 == #2, 2, Abs[#1 - #2] == 1, -1, True, 0] &, {10, 10}]