# Calculate n-order determinant

Calculate n-order determinant (n>=2):

$$\left|\begin{array}{ccccc}x_{1}-a_{1} & x_{2} & x_{3} & \cdots & x_{n} \\ x_{1} & x_{2}-a_{2} & x_{3} & \cdots & x_{n} \\ x_{1} & x_{2} & x_{3}-a_{3} & \cdots & x_{n} \\ \vdots & \vdots & \vdots & & \vdots \\ x_{1} & x_{2} & x_{3} & \cdots & x_{n}-a_{n}\end{array}\right|$$

$$a_{i} \neq 0, i=1,2, \cdots, n$$

The result should be

$$(-1)^{n-1} a_{1} a_{2} a_{3} \cdots a_{n}\left(\sum_{i=1}^{n} \frac{x_{i}}{a_{i}}-1\right)$$

I want to use the FindSequenceFunction to get the result. Here is my code:

Clear["Global*"];
Format[a[n_]] := Subscript[a, n];
Format[x[n_]] := Subscript[x, n];

NewMatrix[n_Integer?Positive] :=
Module[{i = 1, j = 1, M = Array[m, {n, n}]},
For[i = 1, i <= n, i++,
For[j = 1, j <= n, j++,
If[j == i, m[i, j] = x[j] - a[j], m[i, j] = x[j]]]]; M]

tab = Table[Det[NewMatrix[i]], {i, 2, 10}]


$$\left\{a_{1} a_{2}-a_{2} x_{1}-a_{1} x_{2},-a_{1} a_{2} a_{3}+a_{2} a_{3} x_{1}+a_{1} a_{3} x_{2}+a_{1} a_{2} x_{3}, a_{1} a_{2} a_{3} a_{4}-a_{2} a_{3} a_{4} x_{1}-a_{1} a_{3} a_{4} x_{2}-a_{1} a_{2} a_{4} x_{3}-a_{1} a_{2} a_{3} x_{4},\right.$$, $$-a_{1} a_{2} a_{3} a_{4} a_{5}+a_{2} a_{3} a_{4} a_{5} x_{1}+a_{1} a_{3} a_{4} a_{5} x_{2}+a_{1} a_{2} a_{4} a_{5} x_{3}+a_{1} a_{2} a_{3} a_{5} x_{4}+a_{1} a_{2} a_{3} a_{4} x_{5},$$, $$a_{1} a_{2} a_{3} a_{4} a_{5} a_{6}-a_{2} a_{3} a_{4} a_{5} a_{6} x_{1}-a_{1} a_{3} a_{4} a_{5} a_{6} x_{2}-a_{1} a_{2} a_{4} a_{5} a_{6} x_{3}-a_{1} a_{2} a_{3} a_{5} a_{6} x_{4}-a_{1} a_{2} a_{3} a_{4} a_{6} x_{5}-a_{1} a_{2} a_{3} a_{4} a_{5} x_{6},-a_{1} a_{2} a_{3} a_{4} a_{5} a_{6} a_{7}+$$ $$\left.\quad a_{2} a_{3} a_{4} a_{5} a_{6} a_{7} x_{1}+a_{1} a_{3} a_{4} a_{5} a_{6} a_{7} x_{2}+a_{1} a_{2} a_{4} a_{5} a_{6} a_{7} x_{3}+a_{1} a_{2} a_{3} a_{5} a_{6} a_{7} x_{4}+a_{1} a_{2} a_{3} a_{4} a_{6} a_{7} x_{5}+a_{1} a_{2} a_{3} a_{4} a_{5} a_{7} x_{6}+a_{1} a_{2} a_{3} a_{4} a_{5} a_{6} x_{7}\right\}$$

Then,

FindSequenceFunction[tab, n]


FindSequenceFunction $$[\left\{a_{1} a_{2}-a_{2} x_{1}-a_{1} x_{2},-a_{1} a_{2} a_{3}+a_{2} a_{3} x_{1}+a_{1} a_{3} x_{2}+a_{1} a_{2} x_{3}, a_{1} a_{2} a_{3} a_{4}-a_{2} a_{3} a_{4} x_{1}-a_{1} a_{3} a_{4} x_{2}-a_{1} a_{2} a_{4} x_{3}-a_{1} a_{2} a_{3} x_{4},\right.$$, $$-a_{1} a_{2} a_{3} a_{4} a_{5}+a_{2} a_{3} a_{4} a_{5} x_{1}+a_{1} a_{3} a_{4} a_{5} x_{2}+a_{1} a_{2} a_{4} a_{5} x_{3}+a_{1} a_{2} a_{3} a_{5} x_{4}+a_{1} a_{2} a_{3} a_{4} x_{5},$$, $$a_{1} a_{2} a_{3} a_{4} a_{5} a_{6}-a_{2} a_{3} a_{4} a_{5} a_{6} x_{1}-a_{1} a_{3} a_{4} a_{5} a_{6} x_{2}-a_{1} a_{2} a_{4} a_{5} a_{6} x_{3}-a_{1} a_{2} a_{3} a_{5} a_{6} x_{4}-a_{1} a_{2} a_{3} a_{4} a_{6} x_{5}-a_{1} a_{2} a_{3} a_{4} a_{5} x_{6},-a_{1} a_{2} a_{3} a_{4} a_{5} a_{6} a_{7}+$$ $$\left.\quad a_{2} a_{3} a_{4} a_{5} a_{6} a_{7} x_{1}+a_{1} a_{3} a_{4} a_{5} a_{6} a_{7} x_{2}+a_{1} a_{2} a_{4} a_{5} a_{6} a_{7} x_{3}+a_{1} a_{2} a_{3} a_{5} a_{6} a_{7} x_{4}+a_{1} a_{2} a_{3} a_{4} a_{6} a_{7} x_{5}+a_{1} a_{2} a_{3} a_{4} a_{5} a_{7} x_{6}+a_{1} a_{2} a_{3} a_{4} a_{5} a_{6} x_{7}\right\},n]$$

It doesn't work.

• I've noticed very few functions that return answers in terms of Sum/Inactive[Sum]. For instance D[], maybe DSolve[], but I don't recall FindSequenceFunction doing it. Is there an example? It might help with finding an approach to the problem. Apr 18 at 15:02
• Sorry, I haven't found such an example so far. I don't know if others can do it. @Michael E2 Apr 19 at 2:18

Not an answer,only a comment about the simple version of how to calculate such determinant.

The matrix can be writed as

$$\begin{pmatrix}1\\1\\ \vdots \\ 1\end{pmatrix}(x_1,x_2,\cdots,x_n)-\mathrm{diagonal}(a_1,a_2,\cdots,a_n)$$

Clear[det];
det[n_Integer?Positive] :=
Det[Transpose[{ConstantArray[1, n]}] . {Array[Indexed[x, #] &, n]} -
DiagonalMatrix[Array[Indexed[a, #] &, n]]];
det[5]


• I'll only note that using the formula here (basically Sherman-Morrison-Woodbury), we have $\det(\mathbf e\mathbf x^\top-\operatorname{diag}(\mathbf a))=\det(-\operatorname{diag}(\mathbf a))(1-\mathbf x^\top(\operatorname{diag}(\mathbf a))^{-1}\mathbf e)=(-1)^n (1-\sum_{j=1}^n\frac{x_j}{a_j})\prod_{j=1}^n a_j$ Jun 4 at 22:42
• To check: Table[Simplify[Det[Transpose[{ConstantArray[1, n]}] . {Array[Indexed[x, #] &, n]} - DiagonalMatrix[Array[Indexed[a, #] &, n]]] == (-1)^n (1 - Sum[Indexed[x, j]/Indexed[a, j], {j, 1, n}]) Product[Indexed[a, j], {j, 1, n}]], {n, 2, 11}]`. Jun 4 at 22:42