Diag

Parent Previous Next

Diag


Generate diagonal matrix or get diagonal vector from a matrix



Syntax


diag(v)

v is a vector

Return a square matrix in which v is put as the main diagonal

diag(v, k)

v is a vector

k is a integer

When v is a vector of n components, returns a square matrix of order n+abs(k), with the elements of v on the kth diagonal.

diag(a, n)

a is a scalar

n is a positive integer

Return a square matrix of order n+1, with a as the kth diagonal.

diag(X)

X is a matrix

Returns the main diagonal of X

diag(X, k)

X is a matrix

k is a integer

Returns a column vector formed from the elements of the kth diagonal of X.


Examples


Input

Output

diag(1+i)

diag(1+i,4)

diag([1, i, 2-i, 3+i])

diag([1, i, 2-i, 3+i], -2)

a = [1,4,7,10,13;2,5,8,11,14;3,6,9,12,15];

diag(a)    

a = [1,4,7,10,13;2,5,8,11,14;3,6,9,12,15];

diag(a, 2)

Created with the Personal Edition of HelpNDoc: Create HTML Help, DOC, PDF and print manuals from 1 single source