# Calculate the inverse of a matrix of variable size

Compute the inverse of the following matrix of size $$n\times n$$: $$\begin{bmatrix} 1 & -0.5 & 0 & 0 & \ldots & 0\\ -0.5 & 1 & -0.5 & 0 & \ldots & 0\\ 0 & -0.5 & 1 & -0.5 & \ldots & 0\\ 0 & 0 & -0.5 & 1 & \ldots & 0 \\ \vdots &\vdots &\vdots &\vdots & \ddots & \vdots\\ 0 & 0 & 0 & 0 & \ldots & 1 \end{bmatrix}^{-1}$$

I've computed the inverse for $$n=2,3,4$$: $$\frac{1}{2}\begin{bmatrix} 3 & 2 & 1 \\ 2 & 4 & 2 \\ 1 & 2 & 3 \end{bmatrix}; \frac{2}{5}\begin{bmatrix} 4 & 3 & 2 & 1 \\ 3 & 6 & 4 & 2 \\ 2 & 4 & 6 & 3 \\ 1 & 2 & 3 & 4 \end{bmatrix}; \frac{1}{3}\begin{bmatrix} 5 & 4 & 3 & 2 & 1 \\ 4 & 8 & 6 & 4 & 2 \\ 3 & 6 & 9 & 6 & 3 \\ 2 & 4 & 6 & 8 & 4 \\ 1 & 2 & 3 & 4 & 5 \end{bmatrix}$$, but I fail to see a pattern here.

The following will not be any kind of proof, just some patterns I've observed. First of all, let's call your matrix $$M_n$$ (the one with 1's and -0.5's, not its inverse), with $$n$$ its dimension. What I first found is regarding its determinant, which seems to verify: $$\det M_n = \frac{n+1}{2^n}$$
Next, it seems that you can multiply $$M_n^{-1}$$ by $$\frac{n+1}{2}$$ in order to obtain a matrix similar to the ones you've provided, so that$$\frac{n+1}{2}\cdot M_n^{-1}=\begin{bmatrix}n & n-1 & n-2 & \dots & 3 & 2 & 1 \\ n-1 & 2(n-1) & 2(n-2) & \dots & 6 & 4 & 2 \\ n-2 & 2(n-2) & 3(n-2) & \dots & 9 & 6 & 3 \\ \dots & \dots & \dots & \dots & \dots & \dots & \dots \\ 3 & 6 & 9 & \dots & 3(n-2) & 2(n-2) & n-2 \\ 2 & 4 & 6 & \dots & 2(n-2) & 2(n-1) & n-1 \\ 1 & 2 & 3 & \dots & n-2 & n-1 &n \end{bmatrix}$$
Take the last row. Focus on all the entries from the first $$n-1$$ columns. All of the entries above this "short row" are precisely the last row's entries multiplied by 2. Let's now take the second to last row, and focus on all the entries from the left until you reach the diagonal (this time, we're leaving out the last two entries from this row). All of the entries above this "short row" are the last row's entries multiplied by 3.
And so on. This defines the matrix well, since the diagonal is defined and $$M_n^{-1}$$ is symmetric because $$M_n$$ is symmetric.