Algosim documentation: diag

diag

Creates a diagonal matrix from a sequence of numbers.

Syntax

Description

Examples

diag(4, 1, 2, 1)
⎛4  0  0  0⎞
⎜0  1  0  0⎟
⎜0  0  2  0⎟
⎝0  0  0  1⎠
diag(❨7, 2, 1, 1, −2❩)
⎛ 7   0   0   0   0⎞
⎜ 0   2   0   0   0⎟
⎜ 0   0   1   0   0⎟
⎜ 0   0   0   1   0⎟
⎝ 0   0   0   0  −2⎠
diag('(0, 1, 2, 1, 0, 1))
⎛0  0  0  0  0  0⎞
⎜0  1  0  0  0  0⎟
⎜0  0  2  0  0  0⎟
⎜0  0  0  1  0  0⎟
⎜0  0  0  0  0  0⎟
⎝0  0  0  0  0  1⎠

See also