<s>[INST] 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.
 [/INST] 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} $$
</s>