# Finding determinant for a matrix with one value on the diagonal and another everywhere else [duplicate]

Let us look the the matrix

$\left(\begin{array}{ccccc} a & b & b & b & b\\ b & a & b & b & b\\ b & b & a & b & b\\ b & b & b & a & b\\ b & b & b & b & a \end{array}\right)$

It has one value, $a$, on the main diagonal, and another value, $b$ everywhere else. Let us assume that we are over a ring and that $a$ is invertible.

I wish to find the determinant of every $n\times n$ matrix of this form ($a$ on the diagonal, $b$ everywhere else). Using row and column operations I have managed to transform the matrix to upper-triangular form and found formula for specific cases. Generalizing it I got to the following formula:

$\det(A) = a\left(a-b\right)^{n-2}\left(a+\left(n-2\right)b-\frac{\left(n-1\right)b^{2}}{a}\right)$

I think I can prove it with row-operations in the general case with a little patience.

However, I'm wondering if there is a "smart" way of getting to this formula that I'm missing and if there is a nicer representation of it. Also, what can be said when $a$ is not invertible? (esp. the case where we are over a field and $a=0$).

## marked as duplicate by Dietrich Burde, Lord Shark the Unknown, Martin Argerami linear-algebra StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Jan 31 at 4:25

Add all the columns to the first column it becomes a column where all its entries equal to $a+(n-1)b$. Now substract the first row from the other rows we obtain the determinant:
$$\left|\begin{array}{ccccc} a+(n-1)b & b &\cdots& b & b & b\\ 0 & a-b &\cdots& 0 & 0 & 0\\ 0 & 0 &\cdots& a-b & 0 & 0\\ 0& 0 &\cdots&\cdot 0 & a-b & 0\\ 0 & 0&\cdots & 0 & 0 & a-b \end{array}\right|=(a+(n-1)b)(a-b)^{n-1}$$
Yes, your matrix is $b J + (a-b)I,$ where $J$ is the matrix of ones. It has rank one, and eigenvalues $n, 0, \dotsc, 0.$ Sine it commutes with the identity (like everything else), the eigenvalues of the sum are $b n + (a-b) = (n-1) b + a,$ and the rest $a-b$s.