# Create a Vandermonde matrix

I want to create a $$n \times n$$ Vandermonde matrix.

How could I set up a matrix, vMatrix so I can just use vMatrix and get an element of the matrix?

Do I have to set up a $$n \times n$$ null matrix first to build it?

xk[k_, n_] := (-1 + k*1/(n/2))
xk[4, 7]
f[x_] := 1/(1 + 25 x^2)
f
fk[n_] := Table[f[xk[i, n]], {i, 0, n}]
fk
PlotPoint[x_] :=
ListPlot[Table[{xk[i, x], Part[fk[x], i + 1]}, {i, 0, x}]]
PlotLine[x_] := Plot[f[i], {i, xk[0, x], xk[x, x]}]
Show[PlotLine, PlotPoint]

getMatrix[N_] := Table[f[i]
$$$$


vMatrix[n_Integer?Positive] :=
Array[x[#1]^(#2 - 1) &, {n, n}]

Format[x[n_]] := Subscript[x, n]

(mat = vMatrix) // MatrixForm Det[mat] // Simplify EDIT: To enable the argument to also be a vector, add to the definition

vMatrix[v_?VectorQ] :=
#^Range[0, Length[v] - 1] & /@ v

mat == vMatrix[Array[x, 5]]

(* True *)

• Solved it with table don't know the Suberscript function will read through that. – Rapiz Dec 1 '19 at 19:32

Just for the sake of some variety:

vandermonde[n_Integer?Positive] :=
Outer[Power, Table[Subscript[x, i], {i, 1, n}], Range[0, n - 1]]

• +1. For further variety, I'd probably write a general-purpose vandermonde and apply to my x array: vandermonde[x_] := Outer[Power, x, Range[0, Length@x - 1]] – Michael E2 Dec 1 '19 at 23:30

I want to create a $$n \times n$$ Vandermonde matrix.

There is an undocumented function for this:

LinearAlgebraPrivateVandermondeMatrix[Array[x, 5], Transpose -> True]
{{1, x, x^2, x^3, x^4},
{1, x, x^2, x^3, x^4},
{1, x, x^2, x^3, x^4},
{1, x, x^2, x^3, x^4},
{1, x, x^2, x^3, x^4}}
`