Group: | Matrix Manipulation |
Topic: | General Commands |
See also: | matrix unit |
Function: | diag | |
Description: | diag creates a diagonal matrix from a vector. |
Usage: | z = diag (x) | |
Input: | ||
x | p x 1 matrix | |
Output: | ||
z | p x p diagonal matrix |
diag(1:4)
Contents of diag [1,] 1 0 0 0 [2,] 0 2 0 0 [3,] 0 0 3 0 [4,] 0 0 0 4