fn

vander

Tensor
vander(x: Tensor, N: int | None = None, increasing: bool = False)
source

Construct a Vandermonde matrix from a 1-D vector.

Given a 1-D input x=(x1,,xn)x = (x_1, \ldots, x_n), returns the n×Nn \times N matrix whose jj-th column is a power of xx:

Vij=xij(increasing)orVij=xiN1j(decreasing, default).V_{ij} \,=\, x_i^{\,j} \quad (\text{increasing}) \qquad\text{or}\qquad V_{ij} \,=\, x_i^{\,N-1-j} \quad (\text{decreasing, default}).

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

xTensor
1-D input of length nn.
Nint or None= None
Number of columns. Defaults to nn (square output).
increasingbool= False
If True powers increase left-to-right (column 0 is x0x^0). Default False matches the classical convention used in polynomial regression.

Returns

Tensor

n×Nn \times N Vandermonde matrix.

Notes

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]), N=3, increasing=True)
Tensor([[1.0000, 1.0000, 1.0000],
        [1.0000, 2.0000, 4.0000],
        [1.0000, 3.0000, 9.0000]])