Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Language Reference

DIAG Function

creates a diagonal matrix

DIAG( argument)

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 statements

     a={4 3,
        2 1};
     c=diag(a);
result in
                C             2 rows      2 cols    (numeric)

                                     4         0
                                     0         1
The statements
     b={1 2 3};
     d=diag(b);
result in
                D             3 rows      3 cols    (numeric)

                                1         0         0
                                0         2         0
                                0         0         3

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.