NumPhp::vander

Generate a Vandermonde matrix.

Description

SciPhp\NdArray NumPhp::vander( array|NdArray $matrix [, int $num ])

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

Parameters

$matrix
An array [1, 2, 3] or a NdArray.   A 1-dim array
$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::vander([1234]);

print 
$m;

The above example will output:

[[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::vander([1234], 3);

print 
$m;

The above example will output:

[[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::vander([123], 5);

print 
$m;

The above example will output:

[[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.
  • NumPhp::triu() - Construct a triangle matrix based on the upper triangle of another one.
  • NumPhp::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.