.BG
.VE $Header: /usr3/s/current/s/.help/RCS/diag,v 1.2 83/12/30 19:27:40 rab Exp $
.FN diag
.TL
diag: Diagonal Matrices
.CS
diag(x, nrow, ncol)
.PP
.AG x
matrix or vector.
Missing values (NAs) are allowed.
.AG nrow
optional number of rows of output matrix.
.AG ncol
optional number of columns of output matrix.
.RT
the vector of diagonal elements of `x',
if `x' is a matrix.
Otherwise, a matrix with `x' on its diagonal and zeroes
elsewhere. If `x' is a scalar (vector of length 1), the value is an `x' by
`x' identity matrix.  By default, the
matrix is square with zeros off the diagonal, but it can be
made rectangular by specifying `nrow' and `ncol'.
.EX
diag(xmat)    # extract diagonal

diag(diag(xmat))   # matrix of just diagonal of xmat

diag(5)   # 5 by 5 identity matrix

x[ row(x)==col(x) ] <- diag(y)  # put diagonal of y
   # into diagonal of x
.KW array*
.KW matrix
.KW algebra
.WR
