Symbolic Math Toolbox | Search  Help Desk | |
diag | Examples | See Also |
Create or extract symbolic diagonals.
diag(A,k) diag(A)
diag(A,k)
, where A
is a row or column vector with n
components, returns a square symbolic matrix of order n+abs(k),
with the elements of A
on the k
-th diagonal. k = 0
signifies the main diagonal; k > 0
, the k
-th diagonal above the main diagonal; k < 0
, the k
-th diagonal below the main diagonal.
diag(A,k)
, where A
is a square symbolic matrix, returns a column vector formed from the elements of the k
-th diagonal of A
.
diag(A)
, where A
is a vector with n
components, returns an n
-by-n
diagonal matrix having A
as its main diagonal.
diag(A)
, where A
is a square symbolic matrix, returns the main diagonal of A
.
Suppose
v = [a b c]Then both
diag(v)
and diag(v,0)
return
[ a, 0, 0 ] [ 0, b, 0 ] [ 0, 0, c ]
diag(v,-2)
returns
[ 0, 0, 0, 0, 0] [ 0, 0, 0, 0, 0] [ a, 0, 0, 0, 0] [ 0, b, 0, 0, 0] [ 0, 0, c, 0, 0]Suppose
A = [ a, b, c ] [ 1, 2, 3 ] [ x, y, z ]
diag(A)
returns
[ a ] [ 2 ] [ z ]
diag(A,1)
returns
[ b ] [ 3 ]
tril
, triu