Logo

VANDERMONDE

Updated 2024-03-07 15:44:17.283000

Syntax

SELECT [westclintech].[wct].[VANDERMONDE] (
   <@X, nvarchar(max),>
  ,<@N, int,>)

Description

Use the scalar function VANDERMONDE to return the Vandermonde matrix. The returned matrix will contain N + 1 columns with the columns representing the geometric progress of the input vector x.

\textbf{V}=\begin{bmatrix}1&x_0&x_0^2&x_0^3&\dots&x_0^n\\1&x_1&x_1^2&x_1^3&\dots&x_1^n\\1&x_2&x_2^2&x_2^3&\dots&x_2^n\\1&x_3&x_3^2&x_3^3&\dots&x_3^n\\\vdots&\vdots&\vdots&\vdots&\ddots&\vdots\\1&x_m&x_m^2&x_m^3&\dots&x_m^n\end{bmatrix}

Arguments

@N

The upper bound of the Vandermonde matrix. @N is an expression of type int or of a type that can be implicitly converted to int.

@X

The input vector.

Return Type

nvarchar(max)

Remarks

N must be greater than zero.

Examples

Example #1

VANDERMONDE takes the string representation of the X vector and returns a string value.

SELECT wct.VANDERMONDE('1;2;3;4;5', 3);

This produces the following result.

{"columns":[{"field":"column 1"}],"rows":[{"column 1":"1,1,1,1;1,2,4,8;1,3,9,27;1,4,16,64;1,5,25,125"}]}

Example #2

In this example we use the MATRIX2STRING_q function to create the X vector, the TRANSPOSE function to put that vector into the proper format for the VANDERMONDE function, and the MATRIX function to return the string result as a table in 3rd normal form.

DECLARE @X as nvarchar(max) = wct.MATRIX2STRING_q('SELECT 1,1/2e+0,1/3e+0,1/4e+0,

          1/5e+0');

SELECT [0],

       [1],

       [2],

       [3],

       [4],

       [5]

FROM wct.MATRIX(wct.VANDERMONDE(wct.TRANSPOSE(@X), 5))

    PIVOT

    (

        MAX(ItemValue)

        FOR ColNum in ([0], [1], [2], [3], [4], [5])

    ) d

ORDER BY RowNum;

This produces the following result.

{"columns":[{"field":"0","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"2","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"3","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"4","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"5","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"0":"1","1":"1","2":"1","3":"1","4":"1","5":"1"},{"0":"1","1":"0.5","2":"0.25","3":"0.125","4":"0.0625","5":"0.03125"},{"0":"1","1":"0.333333333333333","2":"0.111111111111111","3":"0.0370370370370369","4":"0.0123456790123456","5":"0.00411522633744854"},{"0":"1","1":"0.25","2":"0.0625","3":"0.015625","4":"0.00390625","5":"0.0009765625"},{"0":"1","1":"0.2","2":"0.04","3":"0.008","4":"0.0016","5":"0.00032"}]}

See Also

EYE - Generate an m-by-n identity matrix.

ONES - create an m-by-n matrix of ones

ZERO - Generate an m-by-n matrix of zeroes.