Calculate the determinant of the matrix $(a_{ij})$ where $a_{ij}=a+b$ when $i=j$, and $a_{ij}=a$ otherwise The matrix is $n\times n$ , defined as the following:
$$
a_{ij}=\begin{cases} 
a+b & \text{ when  }  i=j,\\ 
a   & \text{ when }   i \ne j 
\end{cases}.
$$
When I calculated it I got the answer of:  $b^n +nab^{n-1}$ , but I saw other solution that said the answer is $b^n + ab^{n-1}$, so I'm not sure. Can you tell me the right solution and show me the steps to calculate it if I'm wrong ? Thank you.
 A: Let the $n \times n$ matrix $A$ be given by $$A = \begin{pmatrix} a+b & a & a & \cdots & a & a \\ a & a+b & a & \cdots & a & a \\ a & a & a+b & \cdots & a & a \\ \vdots & \vdots & \vdots & \ddots & \vdots & \vdots \\ a & a & a & \cdots & a+b & a \\ a & a & a & \cdots & a & a+b \end{pmatrix} $$
Subtracting row $i+1$ from row $i$ for $1 \leq i \leq n-1$ leaves the matrix:
$$A' = \begin{pmatrix} b & -b & 0 & \cdots & 0 & 0 \\ 0 & b & -b & \cdots & 0 & 0 \\ 0 & 0 & b & \cdots & 0 & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots & \vdots \\ 0 & 0 & 0 & \cdots & b & -b \\ a & a & a & \cdots & a & a+b \end{pmatrix} $$
Adding column $j$ to column $j+1$ for $ 1 \leq j \leq n-1$ leaves the matrix:
$$A'' = \begin{pmatrix} b & 0 & 0 & \cdots & 0 & 0 \\ 0 & b & 0 & \cdots & 0 & 0 \\ 0 & 0 & b & \cdots & 0 & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots & \vdots \\ 0 & 0 & 0 & \cdots & b & 0 \\ a & 2a & 3a & \cdots & (n-1)a & na+b \end{pmatrix} $$
As the addition or subtraction of rows and columns does not change the determinant we have $\det(A) = \det(A'')$. Finally, as $A''$ is an upper triangular matrix, it follows that:
$$ \det(A) = b^{n-1}(na+b) = b^n + nab^{n-1} $$
A: Here is another proof that you have computed the determinant correctly:
Let $I$ be the $(n\times n)$ identity matrix and $E$  the  matrix consisting of all ones. Then
$$A=b I+ a E\ .\tag{1}$$ Put $f_1:=(1,1,\ldots,1)$ and choose a basis  $(f_2,f_3,\ldots, f_n)$ of $\langle f_1\rangle^\perp$. As $Ef_j=0$ for $j\geq2$ it follows from  $(1)$  that
$$Af_1=(na+b)f_1,\qquad Af_j= b f_j\quad(2\leq j\leq n)\ .$$
This allows us to conclude that
$$\det(A)=(na+b) b^{n-1}\ .$$
A: The answer you calculated is the correct answer. Just take the determinant of a 2x2 matrix to see that the other solution is incorrect. 
A: Given $m \in \mathbb{N}$ we denote by $e_1^m,\ldots, e_m^m$ the canonical basis of $\mathbb{R}^m$ and by $u^m$ the element of $\mathbb{R}^m$ whose components are all equal to $1$. Denote the determinant of the given matrix by $d_n$. We have
$$
d_1=a+b,\ d_2=(a+b)^2-a^2=(2a+b)b.
$$
For $n \ge 3$ we have
\begin{eqnarray}
d_n&=&\det(au^n+be_1^n,au^n+be_2^n,\ldots,au^n+be_n^n)\\
&=&a\det(u^n,au^n+be_2^n,\ldots,au^n+be_n^n)+b\det(e_1^n,au^n+be_2^n,\ldots,au^n+be_n^n)\\
&=&a\det(u^n,be_2^n,\ldots,be_n^n)+b\det(au^{n-1}+be_1^{n-1},\ldots,au^{n-1}+be_{n-1}^{n-1})\\
&=&ab^{n-1}+b\det(au^{n-1}+be_1^{n-1},\ldots,au^{n-1}+be_{n-1}^{n-1})\\
&=&ab^{n-1}+bd_{n-1}\\
&=&ab^{n-1}+b(ab^{n-2}+bd_{n-2})\\
&=&2ab^{n-1}+b^2d_{n-2}\\
&=&2ab^{n-1}+b^2(ab^{n-3}+bd_{n-3})\\
&=&3ab^{n-1}+b^3d_{n-3}\\
&\vdots&\\
&=&(n-1)ab^{n-1}+b^{n-1}d_1\\
&=&(n-1)ab^{n-1}+b^{n-1}(a+b)=(na+b)b^{n-1}.
\end{eqnarray}
