|MATLAB Function Reference|
Diagonal matrices and diagonals of a matrix
X = diag(v,k)
v is a vector of
n components, returns a square matrix
X of order
n+abs(k), with the elements of
v on the
k = 0 represents the main diagonal,
k > 0 above the main diagonal, and
k < 0 below the main diagonal.
X = diag(v)
v on the main diagonal, same as above with
v = diag(X,k)
X, returns a column vector
v formed from the elements of the
kth diagonal of
v = diag(X)
returns the main diagonal of
X, same as above with
diag(diag(X)) is a diagonal matrix.
sum(diag(X)) is the trace of
produces a tridiagonal matrix of order
© 1994-2005 The MathWorks, Inc.