DIAG

 

 Create or extract diagonals.

  If V is a row or column vector with N components,

  DIAG(V,K) is a square matrix of order N+ABSMJNRU2(K) with the

  elements of V on the K-th diagonal. K = 0 is the main

  diagonal, K > 0 is above the main diagonal and K < 0 is

  below the main diagonal. DIAG(V) simply puts V on the

  main diagonal. For example,

  DIAG(-M:M) + DIAG(ONES1AWQRU2(2*M,1),1) + DIAG(ONES1AWQRU2(2*M,1),-1)

  produces a tridiagonal matrix of order 2*M+1.

 

 

  If X is a matrix, DIAG(X,K) is a column vector formed from

  the elements of the K-th diagonal of X. DIAG(X) is the main

  diagonal of X. DIAG(DIAG(X)) is a diagonal matrix.