<s>[INST] How to calculate the determinant of $4 \times 4$ matrix with a variable on the diagonal? I need to calculate the determinant of the following $4 \times 4$ matrix:
\begin{bmatrix}x&1&1&1\\1&x&1&1\\1&1&x&1\\1&1&1&x\end{bmatrix}
I heard there is a way by separating the matrix into blocks, but I couldn't succeed in doing that.
 [/INST] In the special case $$
\left( {\begin{array}{*{20}c}
   A & B  \\
   B & A  \\
\end{array}} \right)
$$
where $A,B$ are $2×2$ blocks you can use the formula
$$
\det \left( {\begin{array}{*{20}c}
   A & B  \\
   B & A  \\
\end{array}} \right) = \det \left( {A - B} \right)\det \left( {A + B} \right)
$$
In our case you have
$$
\det \left( {A - B} \right) = \det \left( {\begin{array}{*{20}c}
   {x - 1} & 0  \\
   0 & {x - 1}  \\
\end{array}} \right) = (x - 1)^2 
$$
while
$$
\det \left( {A + B} \right) = \det \left( {\begin{array}{*{20}c}
   {x + 1} & 2  \\
   2 & {x + 1}  \\
\end{array}} \right) = x^2  + 2x - 3 = \left( {x - 1} \right)\left( {x + 3} \right)
$$
whence
$$
\det \left( {\begin{array}{*{20}c}
   A & B  \\
   B & A  \\
\end{array}} \right) = \left( {x - 1} \right)^3 \left( {x + 3} \right)
$$
</s>