Back to Arrays
diag
Square matrix with the given vector on its main diagonal.
Syntax
diag(v) → n×n matrix with v on the diagonal, zeros elsewhere
Backends
TypeScript
Description
Square matrix with the given vector on its main diagonal.
Parameters
| Name | Description |
|---|---|
| v | Diagonal values |
Returns
n×n matrix with v on the diagonal, zeros elsewhere
Examples
Try It
>> diag([1, 2, 3])