>cofactors ( matrix -- matrix' )
Extra matrix operations

Prev:>minors ( matrix -- matrix' )
Next:multiplicative-inverse ( x -- y )


Vocabulary
math.matrices.extras

Inputs
matrixa matrix


Outputs
matrix'a matrix


Word description
Calculate the matrix of cofactors of the input matrix. See matrix of cofactors on Wikipedia. Alternating elements of the input matrix have their signs inverted.

On odd rows, the even elements have their signs inverted. On even rows, odd elements have their signs inverted.

Notes
The shape of the input matrix is preserved in the output.
This word is intended for use with "flat" (2-dimensional) matrices.
This word assumes that elements of the input matrix are compatible with the following words:
neg ( x -- -x )


Examples
USING: math.matrices.extras prettyprint ; { { 8 0 7 11 } { 15 0 3 11 } { 1 10 4 6 } { 11 15 3 15 } } >cofactors .
{ { 8 0 7 -11 } { -15 0 -3 11 } { 1 -10 4 -6 } { -11 15 -3 15 } }

USING: math.matrices.extras prettyprint ; { { -8 0 7 -11 } { 15 0 -3 -11 } { 1 -10 -4 6 } { 11 -15 3 -15 } } >cofactors .
{ { -8 0 7 11 } { -15 0 3 -11 } { 1 10 -4 -6 } { -11 -15 -3 -15 } }


Definition