# 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[5] 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[6]
fk[n_] := Table[f[xk[i, n]], {i, 0, n}]
fk[10]
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[10], PlotPoint[10]]

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


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

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

(mat = vMatrix[5]) // 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[1], x[1]^2, x[1]^3, x[1]^4},
{1, x[2], x[2]^2, x[2]^3, x[2]^4},
{1, x[3], x[3]^2, x[3]^3, x[3]^4},
{1, x[4], x[4]^2, x[4]^3, x[4]^4},
{1, x[5], x[5]^2, x[5]^3, x[5]^4}}
`