Algosim documentation: MainDiagonal

MainDiagonal

Represents the main diagonal in a matrix.

Syntax

The returned value is an lvalue.

Description

If A is a matrix, not necessarily square, then MainDiagonal(A) represents the main diagonal in A, that is, the entries A[i, j] where i = j.

Typewise, MainDiagonal(A) is a vector.

MainDiagonal(A) is an lvalue, so it may be assigned to. If A is a real matrix, then only a real vector can be assigned to it.

Examples

A ≔ ❨❨1, 2, 3❩, ❨5, 1, 2❩, ❨6, 6, 5❩, ❨4, 2, 1❩❩
⎛1  2  3⎞
⎜5  1  2⎟
⎜6  6  5⎟
⎝4  2  1⎠
MainDiagonal(A)
 ⎛1⎞
e⎜1⎟
 ⎝5⎠
MainDiagonal(A) ≔ ❨3, 9, 4❩
 ⎛3⎞
e⎜9⎟
 ⎝4⎠
A
⎛3  2  3⎞
⎜5  9  2⎟
⎜6  6  4⎟
⎝4  2  1⎠

See also