<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] Useful trick - if the sum of each row of the matrix is the same (in this case - $x+3$), then you can simplify the determinant via the following elementary operations:

*

*Add all columns to the first column.


*Subtract the first row from all rows.
In your case:
$$\begin{vmatrix}x&1&1&1\\1&x&1&1\\1&1&x&1\\1&1&1&x\end{vmatrix}
=\begin{vmatrix}x+3&1&1&1\\x+3&x&1&1\\x+3&1&x&1\\x+3&1&1&x\end{vmatrix}
=\begin{vmatrix}x+3&1&1&1\\0&x-1&0&0\\0&0&x-1&0\\0&0&0&x-1\end{vmatrix}$$
Your matrix is now triangular, and the determinant is the product of diagonal elements.
</s>