main-diagonal ( matrix -- seq )

Matrix operations

Matrix operations

Prev: | stitch ( m -- m' ) |

Next: | anti-diagonal ( matrix -- seq ) |

Vocabulary

math.matrices

Inputs

Outputs

Word description

Find the main diagonal of a matrix.

This diagonal begins in the upper left of the matrix at index { 0 0 }, continuing downward and rightward for all indices { n n } in the square-matrix subset of the input (see <square-rows> ).

Notes

Examples

The operation is simple on a square-matrix:

The square subset of the following input matrix consists of all rows but the last. The main diagonal does not include the last row because it has no fourth element.

Definition

math.matrices

Inputs

matrix | a matrix |

Outputs

seq | a sequence |

Word description

Find the main diagonal of a matrix.

This diagonal begins in the upper left of the matrix at index { 0 0 }, continuing downward and rightward for all indices { n n } in the square-matrix subset of the input (see <square-rows> ).

Notes

• | If the number of rows in the square subset of the input is even, then this diagonal will not contain elements found in the anti-diagonal. However, if the size of the square subset is odd, then this diagonal will share at most one element with anti-diagonal. |

• | This diagonal is sometimes called the first diagonal. |

• | This word is the opposite variant of anti-diagonal. |

Examples

The operation is simple on a square-matrix:

USING: math.matrices prettyprint ;
{
{ 7 2 11 }
{ 9 7 7 }
{ 1 8 0 }
} main-diagonal .

{ 7 7 0 }

{ 7 7 0 }

The square subset of the following input matrix consists of all rows but the last. The main diagonal does not include the last row because it has no fourth element.

USING: math.matrices prettyprint ;
{
{ 6 5 0 }
{ 7 2 6 }
{ 4 3 9 }
{ 3 3 3 }
} main-diagonal .

{ 6 2 9 }

{ 6 2 9 }

Definition

This documentation was generated offline from a
`load-all`

image. If you want, you can also
browse the documentation from within the UI developer tools. See
the Factor website
for more information.

Factor 0.99 x86.64 (2190, heads/master-46c625f8dc, Feb 4 2023 19:37:27)