Inverse of a tridiagonal matrix with all entries unity. Suppose we consider the tridiagonal matrix of size $n \times n$
$$A = \begin{pmatrix}1&1&&&\\ 1&1&1&\ddots\\ &\ddots&\ddots&\ddots\\ &&1&1&1\\ &&&1&1\end{pmatrix}$$
I am thinking if there is a  general form of the matrix $A^{-1}$?
I have observed numerically that when $n$ is of the form $3k$ or $3k-2$, then the determinant of $A$ is $-1$ and $1$ respectively. If $n$ is of the form $3k-1$, then $det(A) = 0$, where $k \in \Bbb{N}$ and $k \geq 2$.
 A: Here is an answer inspired (in particular) by the answer by Calvin Lin to this question.
Let us give the indexed name $A_n$ in the case $A$ is $n \times n$. Let $D_n$ denote its determinant. We have in particular
$$D_1=1, \ \ D_2=0 \tag{1}$$
Using two successive Laplace expansions of $D_n$ with respect to columns, one obtains the recurrence relationship:
$$D_n=D_{n-1}-D_{n-2}\tag{2}$$
(2) is a linear recurrence relationship with constant coefficients and initial conditions (1) ; it has a unique solution which cannot be "eyeballed".
The characteristic equation of (2) is $x^2-x+1=0$.
Its two roots are
$$\frac{1 \pm \sqrt{3}i}{2}= w \ or \ \bar{w} \ \text{with} \ w:=e^{i \pi/3}.$$
Therefore, the solution of (2) has the form:
$$D_n=aw^n+b\bar{w}^n\tag{3}$$
for certain constants $a$ and $b$.
Taking into account the "initial conditions" (1), we must have:
$$\begin{cases}aw+b \bar{w}&=&1\\aw^2+b \bar{w}^2&=&0\end{cases},$$
a linear system whose solution is:
$$a=\frac{-iw}{\sqrt{3}}, \ \ b=\frac{i \bar{w}}{\sqrt{3}}\tag{4}$$
Plugging (4) into (3), we get:
$$D_n=\frac{i}{\sqrt{3}}\left(-w w^n+\bar{w}\bar{w}^n\right)=\frac{i}{\sqrt{3}}\left(- w^{n+1}+\bar{w}^{n+1}\right)$$
$$D_n=\frac{2}{\sqrt{3}}\sin \left((n+1)\frac{\pi}{3}\right)$$
Please note that the final expression is real.
