Home > @josh-brown/vector > MatrixBuilder > pascal
Constructs a lower-triangular matrix whose entries are the binomial coefficients (j choose i). Constructs an upper triangular matrix when the second argument is true.
Signature:
pascal(size: number, upper?: boolean): M;|
Parameter |
Type |
Description |
|---|---|---|
|
size |
number |
The size of the Pascal matrix |
|
upper |
boolean |
(Optional) Construct an upper-triangular matrix (i choose j) |
Returns:
M
const pascalLower = matrixBuilder.pascal(4);
// [ 1 0 0 0 ]
// [ 1 1 0 0 ]
// [ 1 2 1 0 ]
// [ 1 3 3 1 ]
const pascalUpper = matrixBuilder.pascal(4, true);
// [ 1 1 1 1 ]
// [ 0 1 2 3 ]
// [ 0 0 1 3 ]
// [ 0 0 0 1 ]