Language Reference |
creates a diagonal matrix
where argument can be either a numeric square matrix or a vector.
If argument is a square matrix, the DIAG function creates a matrix with diagonal elements equal to the corresponding diagonal elements. All off-diagonal elements in the new matrix are zeros.
If argument is a vector, the DIAG function creates a matrix with diagonal elements that are the values in the vector. All off-diagonal elements are zeros.
For example, the following statements produce the matrix , as shown:
a={4 3, 2 1}; c=diag(a);
C 2 rows 2 cols (numeric) 4 0 0 1The following statements produce the matrix , as shown:
b={1 2 3}; d=diag(b);
D 3 rows 3 cols (numeric) 1 0 0 0 2 0 0 0 3
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.