David
Farruggio

MathGenie

diag

Create diagonal matrix or get diagonal elemen

Syntax and Description

diag(v) returns a square diagonal matrix with the elements of vector v on the main diagonal.
diag(v,k) places the elements of vector v on the kth diagonal. k=0 represents the main diagonal, k>0 is above the main diagonal, and k<0 is below the main diagonal.
diag(A) returns a column vector of the main diagonal elements of A.
diag(A,k) returns a column vector of the elements on the kth diagonal of A.

Back to functions