TITLE: Determinant of matrix with constant lines apart diagonal
QUESTION [6 upvotes]: I would like to compute the determinant of a matrix with the following structure:
\begin{equation}
\begin{pmatrix}
D_1 & l_1 & l_1 &\cdots & l_1 \\
l_2 & D_2 & l_2 &\cdots & l_2 \\
l_3 & \cdots & D_3  &\cdots & l_3 \\
l_4 & \cdots & l_4 & D_4  & l_4 \\
l_5 & \cdots & \cdots & l_5 & D_5  \\
\end{pmatrix}
\end{equation}
That is, it is constant on each line apart from the diagonal.
$l_i, D_i \in \mathbb R^+$. 
Is there a way to make use of such symmetric structure to simplify the calculation of the determinant?

REPLY [9 votes]: One has :
$$
\begin{pmatrix}
D_1 & l_1 & l_1 &\cdots & l_1 \\
l_2 & D_2 & l_2 &\cdots & l_2 \\
l_3 & \cdots & D_3  &\cdots & l_3 \\
l_4 & \cdots & l_4 & D_4  & l_4 \\
l_5 & \cdots & \cdots & l_5 & D_5  \\
\end{pmatrix}=$$
$$
\begin{pmatrix}
D_1-l_1 & & &&  \\
 & D_2-l_2 &  && \\
& & D_3-l_3  && \\
& &  & D_4-l_4 & \\
 &  &  &  & D_5-l_5  \\
\end{pmatrix}+\begin{pmatrix}
l_1\\
l_2\\
l_3\\
l_4\\
l_5  \\
\end{pmatrix}
\begin{pmatrix}
1&1&1&1&1
\end{pmatrix}$$
Now apply the matrix-determinant lemma :
$$\displaystyle \det \left(\mathbf {A} +\mathbf {uv} ^{\textsf {T}}\right)=\left(1+\mathbf {v} ^{\textsf {T}}\mathbf {A} ^{-1}\mathbf {u} \right)\,\det \left(\mathbf {A} \right)$$
dealing with the determinant of a rank-one update to a matrix.
finally giving
$$\displaystyle (1 + \sum_{i=1}^n \frac{l_i}{D_i - l_i}) \prod_{i=1}^n (D_i - l_i) = \prod_{i=1}^n (D_i - l_i) + \sum_{i=1}^n l_i \prod_{j \ne i} (D_j - l_j)$$
as explicited by  @math54321 who has pointed the fact that it isn't necessary to assume that the diagonal matrix with diagonal elements $D_i-l_i$ is invertible ; the non-inversibility case can be treated by using a slightly different version of the matrix-determinant lemma which is 
$$\displaystyle \det \left(\mathbf {A} +\mathbf {uv} ^{\textsf {T}}\right)=\det \left(\mathbf {A} \right)+\mathbf {v} ^{\textsf {T}}\mathrm {adj} \left(\mathbf {A} \right)\mathbf {u}$$