diag(what, offset)

Diagonal matrix.

diag([1,2,3])
whatA row vector or a scalar. These elements will be inserted in the diagonal of the resulting matrix.
offsetUsed to insert zero rows/colums in the matrix (optional). See description above.
return valueA square matrix with the given elements in its diagonal.

Creates a diagonal matrix from a row vector given by the argument what. If offset is given, the resulting matrix will be padded in either of two ways:
- If offset is positive, offset number of columns of zeros will be inserted on the left side, and the same number of will be rows inserted at the bottom of the matrix.
- If offset is negative, offset number of columns of zeros will be inserted on the right side, and the same number of rows will be inserted at the top of the matrix.
The result is always a square matrix.