# 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]
$$$$

• The code in this post looks very much like the code posted here under the user name "Rack Cloud". Dec 1, 2019 at 18:19
• yeah i have 2 stackaccounts due to the fact that some subforums have a question limit Dec 1, 2019 at 19:32
• Possible duplicate of Getting the $x$ values to generate a list plot for a given function Dec 2, 2019 at 7:29
• Not quite the solution that's the easiest to understand, but you can use DesignMatrix for this. E.g., DesignMatrix[Array[{x[#], 1} &, 5], y^Range, y]. Jul 18, 2022 at 21:01

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. Dec 1, 2019 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]] Dec 1, 2019 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}}


Edit 7/19/2022

In the current version, the following should be evaluated instead:

StructuredArray$$$$VandermondeMatrix[Array[x, 5], List]