Find the determinant of $n\times n$ matrix

Suppose, $ M=\begin{bmatrix}\begin{array}{ccccccc}
-x & a_2&a_3&a_4&\cdots &a_n\\
a_{1} & -x & a_3&a_4&\cdots &a_n\\
a_1&a_{2} & -x &a_4&\cdots &a_n\\
\vdots&\vdots&\vdots&\vdots &\ddots&\vdots\\
a_1&a_{2} & a_3&a_4&\cdots & -x\\
\end{array}\end{bmatrix}$, then how to find the $\det (M)$?

Solutions Collecting From Web of "Find the determinant of $n\times n$ matrix"

Subtract the first row from each of the other rows. Most of the terms are now zero, and you can expand across the first row. Each product misses one of the $(x+a_i)$ factors, replaced by $a_i$. So the determinant is
$$(-1)^n\prod_i(x+a_i)\left[\frac x{x+a_1}-\frac {a_2}{x+a_2}-\frac {a_3}{x+a_3}…\right]\\
=(-1)^n\prod_i(x+a_i)\left[1-\sum_i\frac{a_i}{x+a_i}\right]$$

Let $D=-\operatorname{diag}(x+a_1,\,\ldots,\,x+a_n)$. Then $M=D+ea^T$. Using the rank-1 update formula for determinant, we have
$\det M=(1+a^TD^{-1}e)\det(D)$. After some work, you should be able to prove that the determinant is
$$(-1)^n\left[\prod_i (x+a_i)-\sum_ia_i\prod_{j\ne i}(x+a_j)\right].$$

The empirical formula I got from considering $n=2,3,4$ in Wolfram Alpha is
$$
(-1)^n(x^n-\sum_{k=2}^n (k-1)\sigma_k x^{n-k})
$$
where $\sigma_k$ is the $k$-th elementary symmetric polynomial in $a_1,\dots,a_n$.

I don’t see how this follows at once from the other answers.

Hint: $\det(M)$ is a polynomial in $x$ and $M$ is clearly singular if $x=-a_k$ for some $k$