MTM - Maple Help

Home : Support : Online Help : Connectivity : MTM Package : MTM/diag

MTM

 diag
 extract the diagonals from a matrix or create a diagonal matrix

 Calling Sequence diag(A) diag(A, k)

Parameters

 A - matrix, vector, array, or scalar k - (optional) integer

Description

 • For a matrix A, the diag(A) command returns the main diagonal of A as a (column) vector.
 • For a matrix A, the diag(A, k) command returns the (column) vector corresponding to the diagonal of A, specified by the selection parameter k.
 • For a vector A, the diag(A) command returns a matrix with the entries of A along the main diagonal, and 0 everywhere else.
 • For a vector A, the diag(A, k) command returns a matrix with the entries of A along the diagonal specified by the selection parameter k.
 • The diagonals of a matrix are indexed using signed integers, where the main diagonal has index 0. Superdiagonals are indexed with positive integers and subdiagonals are indexed with negative integers.

Examples

 > $\mathrm{with}\left(\mathrm{MTM}\right):$
 > $A≔\mathrm{Matrix}\left(\left[\left[1,2,1\right],\left[4,5,6\right],\left[2,8,1\right]\right]\right)$
 ${A}{:=}\left[\begin{array}{rrr}{1}& {2}& {1}\\ {4}& {5}& {6}\\ {2}& {8}& {1}\end{array}\right]$ (1)
 > $\mathrm{diag}\left(A\right)$
 $\left[\begin{array}{r}{1}\\ {5}\\ {1}\end{array}\right]$ (2)
 > $\mathrm{diag}\left(A,1\right)$
 $\left[\begin{array}{r}{2}\\ {6}\end{array}\right]$ (3)
 > $\mathrm{diag}\left(A,-1\right)$
 $\left[\begin{array}{r}{4}\\ {8}\end{array}\right]$ (4)
 > $B≔\mathrm{Vector}\left(\left[4,5,6\right]\right)$
 ${B}{:=}\left[\begin{array}{r}{4}\\ {5}\\ {6}\end{array}\right]$ (5)
 > $\mathrm{diag}\left(B\right)$
 $\left[\begin{array}{rrr}{4}& {0}& {0}\\ {0}& {5}& {0}\\ {0}& {0}& {6}\end{array}\right]$ (6)
 > $\mathrm{diag}\left(B,1\right)$
 $\left[\begin{array}{rrrr}{0}& {4}& {0}& {0}\\ {0}& {0}& {5}& {0}\\ {0}& {0}& {0}& {6}\\ {0}& {0}& {0}& {0}\end{array}\right]$ (7)
 > $\mathrm{diag}\left(B,-1\right)$
 $\left[\begin{array}{rrrr}{0}& {0}& {0}& {0}\\ {4}& {0}& {0}& {0}\\ {0}& {5}& {0}& {0}\\ {0}& {0}& {6}& {0}\end{array}\right]$ (8)