Symbolic Math Toolbox
 Go to function:
  Search    Help Desk 
diag ExamplesSee Also

Create or extract symbolic diagonals.

Syntax

Description

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.

Examples

Suppose

Then both diag(v) and diag(v,0) return

diag(v,-2) returns

Suppose

diag(A) returns

diag(A,1) returns

See Also

tril, triu



[ Previous | Help Desk | Next ]