diagonal

Prev Next

Function Names

diagonal

Description

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.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

1

Parameters

No.TypeDescription
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

Return value

TypeDescription
matrix Output matrix

Contains values across the diagonal

Examples

               echo( diagonal( { 5:1 } ) ); // 5x5 identity matrix
               echo( diagonal( { a, 1, true, 2 } ) );

Output

{{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}}
Try it yourself: Open LIB_Function_diagonal.b4p in B4P_Examples.zip. Decompress before use.

See also

vertical
horizontal
flat
identity