program p0;

uses mtx09;

var
  r, a, b, x1: mtx;
  x: double;

begin
  tra(true);                  // trace on
  equ(a,'1 2 3; 4 5 6;');     //  assign a mtx from a string
  zer(b,lgn(a,1));            //
  add(b,a);                   //  col summation
  add(r,a,b);                 //  expand b to match a
  one(b,col(a,1));            //  élément neutre de la multiplication
  mul(b,a);                   //  row elm/elm product
  prd(r,a,trp(a));            //  r = a * a'
  prd(r,trp(a),a);            //  r = a' * a
  x := prd(lgn(a,1),trp(lgn(a,1))); // square scalar product of a(1,:)
  inv(r,col(a,2,3),x);        // Gauss/Jordan inversion
  mwr(x);                     // kludge to trace the determinant x
  inv(r,x);                   // check inversion accuracy
  stk(a,a);                   // a = [a;a]
  cat(r,col(a,3),col(a,1,2)); // r = [a(:,3),a(:,1:2)]
  zer(x1,col(r,1));           // x1 = zeros(r(:,1))
  cat(r,x1);                  // r  = [r,x1]
  cat(x1,r);                  // x1 = [x1,r]
  equ(r,x1);                  // r = x1
end.
