diagonal
This function converts 1-dimensional vectors (i.e. sets containing values) into 2-dimensional matrices with values arranged diagonally and all remaining values are zero or a different value if specified in the 2nd function parameter.
Indirect parameter passing is disabled
1
No. | Type | Description |
---|---|---|
1 input |
set | input values The values provided will be arranged diagonally into the matrix. |
Opt. 2 input |
valid types | Value outside diagonal The remaining filds (outside the diagonal) will be written with this value provided. Default value: 0 |
Type | Description |
---|---|
matrix | Output matrix Contains values across the diagonal |
echo( diagonal( { 5:1 } ) ); // 5x5 identity matrix
echo( diagonal( { a, 1, true, 2 } ) );
{{1,0,0,0,0},{0,1,0,0,0},{0,0,1,0,0},{0,0,0,1,0},{0,0,0,0,1}}
{{'a',0,0,0},{0,1,0,0},{0,0,true,0},{0,0,0,2}}