Inverse of special type of symmetric block matrix $W = \begin{pmatrix}A & B &B &\cdots&B\\
B& A & B &\cdots &B\\
\vdots & \vdots & \vdots & \ddots &\vdots &\\
B& B & B &\cdots &A \end{pmatrix} $
where $A$ and $B$ are symmetric matrices of appropriate order. In fact $B = aJ$, where $J$ is the matrix of all ones. Is there any compact form of $W^{-1}$ ?. Thanks 
 A: To make the answer below easier to read, I will write the block matrix of interest as $\mathbf{W}$; furthermore, I'll denote elements of block matrices using indices $I,J$ (for regular matrices I'll just use $i,j$). For specificity, I will also assume that $\mathbf{W}$ is block $n$-by-$n$ and $A,B$ are $k$-by-$k$. (If you had other symbols in mind for these dimensions, let me know.) Finally, for later convenience I will define $u_n$ to be the column $n$-vector of ones and $J_n$ the $n$-by-$n$ matrix of ones.
Using the above conventions, the block matrix of interest has elements $$(\mathbf{W})_{IJ}=A \delta_{IJ}+B(1-\delta_{IJ})=(A-B)\delta_{IJ}+B$$ where $\delta_{IJ}$ is the Kronecker delta. If we recall the definition of the Kronecker product and consider the form of $B=aJ_k$, these two terms can be compactly represented as $$\mathbf{W}=I_n\otimes (A-B)+J_n\otimes B=I_n\otimes (A-a J_k)+a J_n\otimes J_k.$$
Furthermore, since $J_n=u_nu_n ^T$ we can write $$J_n\otimes J_k=u_nu_n^T\otimes u_ku_k^T = (u_n\otimes u_k)(u_k^T\otimes u_k^T)=\mathbf{u}\mathbf{u}^T$$ where $\mathbf{u}$ is the column $nk$-vector of ones. But this is a rank-one matrix, so we can express $\mathbf{W}^{-1}$ via the Sherman-Morrison formula:
\begin{align}
\mathbf{W}^{-1}
&=\left[I_n\otimes (A-a J)+a \mathbf{u}\mathbf{u}^T\right]^{-1}\\
&=[I_n\otimes (A-a J_k)]^{-1}-\frac{[I_n\otimes (A-a J_k)]^{-1}a\mathbf{u}\mathbf{u}^T[I_n\otimes (A-a J_k)]^{-1}}{1+a\mathbf{u}^T (I_n\otimes (A-a J_k)^{-1})\mathbf{u}}.\\
&=I_n\otimes (A-a J_k)^{-1}-\frac{(I_n\otimes (A-a J_k)^{-1})(J_n\otimes aJ_k)(I_n\otimes (A-a J_k)^{-1})}{1+a(u_n^T\otimes u_k^T) (I_n\otimes (A-a J_k)^{-1})(u_n\otimes u_k)}.\\
&=I_n\otimes (A-a J_k)^{-1}-\frac{J_n\otimes[(A-a J_k)^{-1}J_k(A-a J_k)^{-1}]}{1+na\cdot u_k^T(A-aJ_k)^{-1}u_k}.
\end{align}
Since $J_k=u_ku_k^T$ is itself a rank-one matrix, we can again appeal to Sherman-Morrison to get $$(A-aJ_k)^{-1}=A^{-1}+A^{-1}\frac{au_ku_k^T}{1-a u_k^TA^{-1}u_k}A^{-1}.$$
This simplifies the product in the denominator to
$$u_k^T(A-aJ_k)^{-1}u_k=u_k^T A^{-1}u_k+(u_k^T A^{-1}u_k)\frac{a}{1-a u_k^TA^{-1}u_k}(u_k^T A^{-1}u_k)=\frac{u_k^T A^{-1}u_k}{1-a u_k^TA^{-1}u_k}.$$
It's possible one could simplify this further but for the time being I'll call it quits here. However, note that $\mathbf{W}^{-1}$ been expressed entirely in terms of $u$ and the matrix inverse $A^{-1}$. (In particular, $u_k^T A^{-1}u_k$ is just the sum of all elements of $A^{-1}$.) So if we already knew $A^{-1}$ then we could compute $\mathbf{W}^{-1}$ directly from the above. 
