Solving this n x n matrix equation with special structure I have a simple linear equation of the form $A\vec{y}=\vec{x}$ for $A$ an $n\times n$ invertible matrix whose diagonal entries are all equal to $a$ and off diagonal entries are all equal to $b$.
Writing $\vec{x}=(x_1,x_2,...,x_n)$, $\vec{y}=(y_1,y_2,...,y_n)$, I want to find the coefficients $c_i$ in $y_1+y_2+...+y_n=\sum_{i=1}^n c_i x_i$. I am looking for an answer in the form of a ratio of two polynomials in $a$ and $b$, which I have found is the case for $n=2$ and $n=3$, for example I found $ y_1+y_2=\frac{a-b}{a^2-b^2}x_1+\frac{a-b}{a^2-b^2}x_2$ for $n=2$.
**edit: using some other means I am fairly certain the answer is $c_i=\frac{1}{a+(n-1)b}$, but I'm not sure how to prove it.
The simplest way to do this would be to find the inverse of $A$, but I am not sure how to do this for general $n$. I found the question Determinant of a specially structured matrix ($a$'s on the diagonal, all other entries equal to $b$) gives the determinant of the matrix $A$, which would be helpful in finding the inverse as well as using another method such as Cramer's Rule.
 A: Write $A=[a_{ij}]_{i,j=1}^n$, i.e., $a_{ij}=\begin{cases}a&\text{if }i=j\\b&\text{if }i\neq j\end{cases}$. Since $Ay=x$, we obtain, by definition of the product of a matrix with a vector,
$$x_i=\sum_{i=1}^n a_{ij}y_j=ay_i+b\sum_{i\neq j}y_j\qquad\text{ for all }i.$$
Summing the equations above for all $i$, we obtain
$$\sum_{i=1}^n x_i=a\sum_{i=1}^n y_i+b\sum_{i=1}^n\sum_{j\neq i}y_j$$
Note that
\begin{align*}
\sum_{i=1}^n\sum_{j\neq i}y_j&=\begin{pmatrix}
&y_2+&y_3+&\cdots+&y_{n-1}+&y_n\\
+y_1+&&y_3+&\cdots+&y_{n-1}+&y_n\\
+y_1+&y_2+&&\cdots+&y_{n-1}+&y_n\\
\vdots&\vdots&\vdots&\ddots&\vdots&\vdots\\
+y_1+&y_2&y_3+&\cdots+&&y_n\\
+y_1+&y_2&y_3+&\cdots+&y_{n-1}&
\end{pmatrix}\\
&=(n-1)y_1+(n-1)y_2+\cdots+(n-1)y_n\\
&=(n-1)\sum_{i=1}^n y_i
\end{align*}
Therefore,
$$\sum_{i=1}^n x_i=a\sum_{i=1}^n y_i+b(n-1)\sum_{i=1}^n y_i=(a+(n-1)b)\sum_{i=1}^n y_i$$
so $\sum_{i=1}^n y_i=\frac{1}{a+(n-1)b}\sum_{i=1}^n x_i$, as you had guessed. (Note that since we assume $A$ invertible, then the question you linked gives $\det A=(a+(n-1)b)(a-b)^{n-1}$, so $a+(n-1)b\neq 0$.)
