# How to calculate the determinant of all-ones matrix minus the identity? [duplicate]

How do I calculate the determinant of the following $$n\times n$$ matrices

$$\begin {bmatrix} 0 & 1 & \ldots & 1 \\ 1 & 0 & \ldots & 1 \\ \vdots & \vdots & \ddots & \vdots \\ 1 & 1 & ... & 0 \end {bmatrix}$$

and the same matrix but one of columns replaced only with $$1$$s?

In the above matrix all off-diagonal elements are $$1$$ and diagonal elements are $$0$$.

• i.e., all the off-diagonal elements are $1$? Commented Nov 21, 2011 at 12:12
• yeah, all off-diagonal elements are 1 and diagonal elements are 0. Commented Nov 21, 2011 at 12:14
• Did you try the first few cases, $n=1,2,3,4$? Here's $n=4$: wolframalpha.com/input/….
– lhf
Commented Nov 21, 2011 at 12:15
• An approach similar to that taken here might work. Commented Nov 21, 2011 at 12:18
• If we call your first matrix as $\mathbf M$, then your second matrix can be written as $\mathbf M+\mathbf e_k\mathbf e_k^\top$, where $\mathbf e_k$ is the $k$-th column of the identity. You can now use this. Commented Nov 21, 2011 at 12:38

$$D_n(a,b)= \begin{vmatrix} a & b & b & b \\ b & a & b & b \\ b & b & a & b \\ b & b & b & a \end{vmatrix}$$ ($n\times n$-matrix).

$$D_n(a,b)= \begin{vmatrix} a & b & b & b \\ b & a & b & b \\ b & b & a & b \\ b & b & b & a \end{vmatrix}$$

$$=[a+(n-1)b] \begin{vmatrix} 1 & 1 & 1 & 1 \\ b & a & b & b \\ b & b & a & b \\ b & b & b & a \end{vmatrix}$$ $$=[a+(n-1)b] \begin{vmatrix} 1 & 1 & 1 & 1 \\ 0 & a-b & 0 & 0 \\ 0 & 0 & a-b & 0 \\ 0 & 0 & 0 & a-b \end{vmatrix}$$ $$=[a+(n-1)b](a-b)^{n-1}$$

(In the first step we added the remaining rows to the first row and then "pulled out" constant out of the determinant. Then we subtracted $b$-multiple of the first row from each of the remaining rows.)

You're asking about $D_n(0,1)=(-1)^{n-1}(n-1)$.

If you replace one column by 1's, you can use this result to get the following. (I've computed it for $n=4$, but I guess you can generalize this for arbitrary $n$.)

$$\begin{vmatrix} 1 & 1 & 1 & 1 \\ 1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 1 \\ 1 & 1 & 1 & 0 \\ \end{vmatrix} = \begin{vmatrix} 0 & 1 & 1 & 1 \\ 1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 1 \\ 1 & 1 & 1 & 0 \\ \end{vmatrix} + \begin{vmatrix} 1 & 0 & 0 & 0 \\ 1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 1 \\ 1 & 1 & 1 & 0 \\ \end{vmatrix}= \begin{vmatrix} 0 & 1 & 1 & 1 \\ 1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 1 \\ 1 & 1 & 1 & 0 \\ \end{vmatrix} + \begin{vmatrix} 0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0 \end{vmatrix}$$

Note that both these determinants are of the type you already handled in the first part.

I will compute the determinant of the matrix $$A = \left( \begin {matrix} b & a & \ldots & a \\ a & b & \ddots & \vdots \\ \vdots & \ddots & \ddots & a \\ a & \cdots & a & b \end {matrix} \right),$$ where $$a, b \in \mathbb{K}$$. To obtain your case, put $$a=1$$ and $$b=0$$.

First proof. This works if $$\mathrm{char}(\mathbb{K}) = 0$$ or $$n$$ is prime to $$\mathrm{char}(\mathbb{K}) > 0$$. If $$a =0$$, then $$\det A = b^n$$. Suppose $$a \neq 0$$ and consider the vector $$v = (1, \dots, 1) \in \mathbb{K}^n$$; it is clear that $$v$$ is an eigenvector of $$A$$ with eigenvalue $$\alpha = (n-1) a + b$$. Now consider $$\beta = b-a$$. $$\beta$$ is an eigenvalue of $$A$$ because $$B = A - \beta I_n = \left( \begin {matrix} a & a & \ldots & a \\ a & a & \ldots & a \\ \vdots & \vdots & \ddots & \vdots \\ a & a & ... & a \end {matrix} \right)$$ has rank $$1$$.

Let $$E_\alpha, E_\beta \subseteq \mathbb{K}^n$$ the eigenspaces of $$A$$ of the eigenvalues $$\alpha, \beta$$. We have $$\alpha \neq \beta$$, $$E_\alpha \cap E_\beta = \{ 0 \}$$ and $$\dim E_\beta = n-1$$, thus $$\mathbb{K}^n = E_\alpha \oplus E_\beta$$ and $$E_\alpha = \langle v \rangle$$. This proves that $$A$$ is similar to the matrix $$\mathrm{diag}(\alpha, \beta, \dots, \beta)$$, therefore $$\det A = \alpha \beta^{n-1} = [(n-1)a +b] (b-a)^{n-1}$$. (Notice that this formula holds also when $$a=0$$.)

Second proof. The characteristic polynomial of the matrix $$B = A - (b-a) I$$ is $$\chi_B(t) = (-t)^n + c_{n-1} (-t)^{n-1} + \cdots + c_1(-t) + c_0,$$ where $$c_i$$ is the sum of the principal $$(n-i)$$-minors of $$B$$. It is clear that all principal minors of $$B$$ are zero, except on $$1$$-minors. Thus $$\chi_B(t) = (-t)^n + na (-t)^{n-1}.$$ From $$A = B + (b-a) I$$, we have $$\chi_A(t) = \chi_B(t-b+a)$$. Thus $$\det A = \chi_A(0) = \chi_B(a-b) = (b-a)^n + na (b-a)^{n-1}$$.

Now consider the matrix $$C = \left( \begin {matrix} a & a & \ldots & a \\ a & b & \ddots & \vdots \\ \vdots & \ddots & \ddots & a \\ a & \cdots & a & b \end {matrix} \right).$$ For every $$i=2,\dots,n$$, replace the $$i$$th row $$C_i$$ of $$C$$ with $$C_i - C_1$$, where $$C_1$$ is the first row of $$C$$. Obtain $$\det C = \det \left( \begin{matrix} a & a & a & \cdots & a \\ 0 & b-a & 0 & \cdots & 0 \\ 0 & 0 & b-a & \ddots & 0 \\ \vdots & \vdots & \ddots & \ddots & 0 \\ 0 & 0 & \cdots & 0 & b-a \end{matrix} \right) = a (b-a)^{n-1}.$$

Here's an approach using Sylvester's determinant theorem, which says that for any rectangular matrices of mutually transposed shapes $A\in\mathrm M_{n,m}(K)$ and $B\in \mathrm M_{m,n}(K)$ one has $$\det(I_n+AB)=\det(I_m+BA).$$

If $N$ is your matrix then $-N=I_n-AB$ where $A\in\mathrm M_{n,1}(K)$ is a one column all-one matrix and $B$ is its transpose. Then $$\det(N)=(-1)^n\det(-N)=(-1)^n\det(I_1-BA)=(-1)^n(1-n).$$

Replace the first 0 with $x$ and the other zeros with $y$.

Now, your determinant is a polynomial in $x$ and $y$ with dominant term $xy^{n-1}$.

If $y=1$, then $n-1$ rows are equal which immediately gives $n-2$ independent kernel vectors, so $(y-1)^{n-2}$ divides the determinant. If $x=(n-1)/(y+n-2)$, then the sum of the $n-1$ bottom lines is a multiple of the first line, so $(x(y+n-2)-(n-1)$ divides the determinant.

Therefore, the determinant is $(x(y+n-2)-(n-1))(y-1)^{n-2}$.

Let $x=y=0$ to get $(-1)^{n-1}(n-1)$.

Let $x=1$ and $y=0$ to get $(-1)^{n-1}$.

Let $E$ be the $(n\times n)$-matrix with all ones and put $f_1:=(1,\ldots,1)$. Then $Ex=(f_1\cdot x)f_1$ for all $x\in{\mathbb R}^n$. Since $A=E-I$ we therefore have

$$Ax\ =\ (f_1\cdot x)f_1 -x\qquad(x\in{\mathbb R}^n)\ .$$

Let $(f_2,\ldots, f_n)$ be a basis of the orthogonal complement of $\langle f_1\rangle$. One has

$$Af_1=(f_1\cdot f_1)f_1 - f_1=(n-1)f_1$$

and

$$Af_i=(f_1\cdot f_i)f_1- f_i=-f_i\qquad(2\leq i\leq n)\ .$$

Therefore the matrix of $A$ with respect to the basis $(f_1,f_2,\ldots, f_n)$ is the diagonal matrix ${\rm diag}(n-1,-1,-1,\ldots,-1)\phantom{\Bigl|}$ and has determinant $(-1)^{n-1}(n-1)$.

This is very close to Christian Blatter's solution:

Let $$E$$ be the $$n$$ by $$n$$ matrix with all coefficients equal to $$1$$.

Let $$H\subset K^n$$ be the hyperplane formed by the vectors whose coordinates add up to $$0$$, and set $$v:=(1,\dots,1)$$.

Then $$H=\ker E$$ and $$Ev=nv$$. This implies
\begin{align} \det(E-X)=(-1)^n\ X^{n-1}\ (X-n), \end{align} and thus \begin{align} \det(E-1)=(-1)^n\ (1-n). \end{align}

Let us denote $A_n$ to be that matrix of order $n \times n$.

Subtract each of the columns multiplied by $1/(n-2)$ from the first column. You determinant then becomes:

$|A_n|= \left| \begin {matrix} \frac {n-1}{n-2} & 1 & \ldots & 1 \\ 0 & 0 & \ldots & 1 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 1 & ... & 0 \end {matrix} \right| = \frac{n-1}{n-2}|A_{n-1}|$

Inductively you get that $|A_n| = \frac{n-1}{n-2} \frac{n-2}{n-3}...\frac{2}{1}|A_2|=(n-1)|A_2|$.

Yet $|A_2|=-1$ so you get that $|A_n|=1-n$.

• $|A_3| = 2$. I think the answer is $(-1)^n(1-n)$.
– lhf
Commented Nov 21, 2011 at 12:41
• True... thanks for your adjustment Commented Nov 21, 2011 at 12:43
• @Shai Note lhf's comment. I think you should have $\left(-\frac{n-1}{n-2}\right)$ instead of $\frac{n-1}{n-2}$. Commented Nov 21, 2011 at 12:43

Let $A_n$ denote the $n\times n$ matrix of the form you give: $0$ on the diagonal and $1$ everywhere else. I'll find $\det A_n$ by computing the eigenvalues of $A_n$ and multiplying them together.

First, let $B_n = A_n + I_n$, so that $B_n$ consists of all $1$'s. Since $B_n$ has rank $1$ it has an eigenvalue $0$ of multiplicity $n-1$; since $\operatorname{tr} B_n = n$ and the trace is the sum of the eigenvalues, the other eigenvalue of $B_n$ must be $n$. Now $v$ is an eigenvector for $B_n$ with eigenvalue $\lambda$ if and only if $v$ is an eigenvector for $A_n$ with eigenvalue $\lambda - 1$ (why?). Hence the eigenvalues of $A_n$ are $$\underbrace{-1,-1,\dots,-1}_{n-1\text{ times}},n-1$$ and $\det A_n = (-1)^{n-1}(n-1)$.

This is similar to a few of the other answers, but I thought it elegant enough to warrant inclusion.