Skip to main content
MedCalc
Mail a PDF copy of this page to:
(Your email address will not be added to a mailing list)
working
Show menu

DIAG matrix function

Description

DIAG(A) Creates a diagonal matrix. The matrix argument can be either a numeric square matrix or a vector.

If matrix A is a square matrix, the DIAG function creates a column vector with its elements er equal to the corresponding diagonal elements er,r of A.

If matrix A is a vector, the DIAG function creates a matrix with diagonal elements er,r that are the values er in the vector. All off-diagonal elements are zeros.

Examples

DIAG({1,9,8}) returns {1,0,0|0,9,0|0,0,8}

DIAG({1,9,8|1,2,7|6,8,3}) returns {1|2|3}

DIAG(DIAG({1,9,8|1,2,7|6,8,3})) returns {1,0,0|0,2,0|0,0,3}

Calculator

DIAG(  

See also

Recommended book

Book cover

Matrix Algebra Useful for Statistics
Shayle R. Searle, Andre I. Khuri

Buy from Amazon

This book addresses matrix algebra that is useful in the statistical analysis of data as well as within statistics as a whole. The material is presented in an explanatory style rather than a formal theorem-proof format and is self-contained.