NdArray::vander

Generate a Vandermonde matrix.

Description

SciPhp\NdArray NdArray::vander( [ int $num ])

The columns of the output matrix are powers of the vector.

Parameters

$num
A positive integer. Number of columns to generate. If not specified, a square array is returned ($num = count($matrix)).

Return Values

A SciPhp\NdArray

Examples

Example #1: Construct a square Vandermonde matrix

use SciPhp\NumPhp as np;

$m np::ar([1234])->vander();

echo 
"m\n$m";

The above example will output:

m
[[1   1   1   1 ]
 [8   4   2   1 ]
 [27  9   3   1 ]
 [64  16  4   1 ]]

Example #2: Construct a Vandermonde matrix with 3 columns

use SciPhp\NumPhp as np;

$m np::ar([1234])->vander(3);

echo 
"m\n$m";

The above example will output:

m
[[1   1   1 ]
 [4   2   1 ]
 [9   3   1 ]
 [16  4   1 ]]

Example #3: Construct a Vandermonde matrix with 5 columns

use SciPhp\NumPhp as np;

$m np::ar([123])->vander(5);

echo 
"m\n$m";

The above example will output:

m
[[1   1   1   1   1 ]
 [16  8   4   2   1 ]
 [81  27  9   3   1 ]]

See Also

  • NumPhp::tri() - Construct an array with ones at and below the given diagonal and zeros elsewhere.
  • NdArray::triu() - Construct a triangle matrix based on the upper triangle of another one.
  • NdArray::tril() - Construct a triangle matrix based on the lower triangle of another one.
  • NumPhp::logspace() - Create a logarithmic range with a defined number of values.