 ArrayTools - Maple Programming Help

Home : Support : Online Help : Programming : Low-level Manipulation : Matrices, Vectors, and Arrays : ArrayTools : ArrayTools/Diagonal

ArrayTools

 Diagonal
 extract the diagonals from a Matrix or create a diagonal Matrix

 Calling Sequence Diagonal(A) Diagonal(A, k)

Parameters

 A - Matrix, Vector, Array, or scalar k - (optional) integer

Description

 • The Diagonal command either creates a matrix with entries on the diagonal, or extracts the entries from the diagonal of a matrix.
 • The Diagonal(A) command returns a matrix with the entries of A along the main diagonal, and 0 everywhere else when A is a vector, or a matrix with one row or column.
 • The Diagonal(A, k) command returns a matrix with the entries of A along the kth diagonal specified by the selection parameter k, and 0 everywhere else, when A is a vector, or a matrix with one row or column.
 • For a matrix A with more than one row and more than one column, the Diagonal(A) command returns the main diagonal of A as a (column) vector.
 • For a matrix A with more than one row and more than one column, the Diagonal(A, k) command returns the (column) vector corresponding to the diagonal of A, 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.
 • This function is part of the ArrayTools package, so it can be used in the short form Diagonal(..) only after executing the command with(ArrayTools). However, it can always be accessed through the long form of the command by using ArrayTools[Diagonal](..).

Examples

 > $\mathrm{with}\left(\mathrm{ArrayTools}\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}{ccc}{1}& {2}& {1}\\ {4}& {5}& {6}\\ {2}& {8}& {1}\end{array}\right]$ (1)
 > $\mathrm{Diagonal}\left(A\right)$
 $\left[\begin{array}{c}{1}\\ {5}\\ {1}\end{array}\right]$ (2)
 > $\mathrm{Diagonal}\left(A,1\right)$
 $\left[\begin{array}{c}{2}\\ {6}\end{array}\right]$ (3)
 > $\mathrm{Diagonal}\left(A,-1\right)$
 $\left[\begin{array}{c}{4}\\ {8}\end{array}\right]$ (4)
 > $B≔\mathrm{Vector}\left(\left[4,5,6\right]\right)$
 ${B}{≔}\left[\begin{array}{c}{4}\\ {5}\\ {6}\end{array}\right]$ (5)
 > $\mathrm{Diagonal}\left(B\right)$
 $\left[\begin{array}{ccc}{4}& {0}& {0}\\ {0}& {5}& {0}\\ {0}& {0}& {6}\end{array}\right]$ (6)
 > $\mathrm{Diagonal}\left(B,1\right)$
 $\left[\begin{array}{cccc}{0}& {4}& {0}& {0}\\ {0}& {0}& {5}& {0}\\ {0}& {0}& {0}& {6}\\ {0}& {0}& {0}& {0}\end{array}\right]$ (7)
 > $\mathrm{Diagonal}\left(B,-1\right)$
 $\left[\begin{array}{cccc}{0}& {0}& {0}& {0}\\ {4}& {0}& {0}& {0}\\ {0}& {5}& {0}& {0}\\ {0}& {0}& {6}& {0}\end{array}\right]$ (8)