Pouring over some matrix theory on the weekends with APL.


In APL:

        sqmat
  2 3
  7 4
        sqmat_transposed ← ⍉sqmat
        sqmat_transposed
  2 7
  3 4
        ⍝ the determinant of a square matrix is equal to the determinant of the transposed matrix
        det sqmat
  ¯13
        det sqmat_transposed
  ¯13
        ⍝ interchanging the rows or columns of a square matrix reverse the sign of its determinant
        det sqmat[2 1;1 2]
  13
        det sqmat[1 2;2 1]
  13
        ⍝ two identical rows or columns of a square matrix has determinant zero
        det (2 2⍴3 1 3 1)
  0
        det (2 2⍴3 3 4 4 )
  0
        ⍝ From Rosetta code we have a simple definition for generating
        ⍝ a n×n identity matrix
        ID ← {∘.=/⍳¨ ⍵ ⍵}    ⍝ create 2 vectors, build an outer product with an equal comparison
        ID 5
   1 0 0 0 0
   0 1 0 0 0
   0 0 1 0 0
   0 0 0 1 0
   0 0 0 0 1
        ⍝ Given Ax = b, we can solve it if we can find a matrix B such that AB = I
        ⍝ If det A = 0, then it implies no such matrix B exists that satisfies the above
        A ← 2 2⍴1 2 3 4
        A
  1 2
  3 4
        det A
  ¯2
        C ← (2 2⍴1 ¯1 ¯1 1) × A[2 1; 2 1]    ⍝ cofactor matrix
        C
   4 ¯3
  ¯2  1
        ⍝ Since the determinant is non-zero, we have
        ⍝ B = (1/det A) × C_transposed
        C_transposed ← ⍉C
        C_transposed
   4 ¯2
  ¯3  1
        (÷det A)
  ¯0.5
        B ← (÷det A) × C_transposed
        B
  ¯2    1
   1.5 ¯0.5
        ⌹A    ⍝ in APL we have this monadic symbol that gives the inverse of a matrix
  ¯2    1
   1.5 ¯0.5
        ⍝ matrix multiplication with +.× should yield the identity matrix
        (A +.× B) ≡ ⊃(ID 2)
  1