Skip to content
fn

vander

→Tensor
vander(x: Tensor, N: int | None = None, increasing: bool = True)

Construct a Vandermonde matrix from a 1-D or batched vector.

Given an input xx of shape (*, n), returns the (*, n, N) tensor whose jj-th column is a power of xx:

V…ij = x…i j(increasing, default)orV…ij = x…i N−1−j(decreasing).V_{\ldots ij} \,=\, x_{\ldots i}^{\,j} \quad (\text{increasing, default}) \qquad\text{or}\qquad V_{\ldots ij} \,=\, x_{\ldots i}^{\,N-1-j} \quad (\text{decreasing}).

Vandermonde matrices arise naturally in polynomial fitting and interpolation: the columns are the basis {1,x,x2,…}\{1, x, x^2, \ldots\} evaluated at the data points.

Parameters

Input tensor of shape (*, n); a 0-d tensor is a vector of one. Floating, complex or integer; an integer input stays integral.
N(int or None, keyword - only)= None
Number of columns. Defaults to nn (square output per vector).
increasing(bool, keyword - only)= True
Default True: column 0 is x0x^0, as the reference orders it. False reverses the columns.

Returns

Tensor

(*, n, N) Vandermonde tensor; int64 for an integer input.

Raises

RuntimeError
If x is a bool tensor (a dtype-mismatch refusal, also a TypeError, as the reference's); cast it first.

Notes

The powers are a running product of x, as the reference builds them, so they are exact for an integer input and the derivative at x=0x = 0 is the exact one. The default was decreasing powers.

Vandermonde matrices become highly ill-conditioned as NN grows (condition number grows exponentially) — for polynomial regression beyond degree ∼10\sim 10 prefer an orthogonal-polynomial basis or QR-based fitting.

Examples

>>> import lucid
>>> from lucid.linalg import vander
>>> vander(lucid.tensor([1.0, 2.0, 3.0]))
tensor([[1., 1., 1.], [1., 2., 4.], [1., 3., 9.]])