
  'Example of Matrix layout in an array
  '
  '  0 4 8 C
  '  1 5 9 D
  '  2 6 A E
  '  3 7 B F
  '
  #define MatrixType double
  'typedef double MatrixType

  uses MatrixMul
  uses MatrixInv

  '-----------------------------------------------
  function showMat(MatrixType *r, sys n) as string
  '===============================================

  string pr
  pr="Matrix:" n "x" n cr
  int i,j,m
  '
  'DISPLAY IN Y MINOR : X MAJOR ORDER (COLUMN MAJOR)
  '-------------------------------------------------
  '
  for i=1 to n
    m=0
    for j=1 to n
      pr+=str( r[m+i] ) tab
      m+=n
    next
    pr+=cr
  next
  return pr cr cr
  '
  end function




  MatrixType m[16],n[16],r[16]

  'set identity matrix values

  ' 1 0 0 0
  ' 0 1 0 0
  ' 0 0 1 0
  ' 0 0 0 1

  'reading vertically then left to right

  m<=1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1
  n<=1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1




  '=====
  'TESTS
  '=====
  '
  string cr=chr(13,10)
  string pr="MATRIX TESTS:" cr cr

  'scalar mul
  int i
  for i=1 to 16 : m[i]*=4 : next
  '
  m[4]=1
  n[4]=1

  MatrixMul m,n,r,4
  '
  pr+=showMat r,4
  MatrixInv   r,4
  pr+="Invert "+showMat r,4
  MatrixInv   r,4
  pr+="Invert again " ShowMat r,4

  print pr

