algebramix_doc 0.3
pivot_test.cpp
/******************************************************************************
* MODULE     : pivot_test.cc
* DESCRIPTION: Test matrices
* COPYRIGHT  : (C) 2004  Joris van der Hoeven
*******************************************************************************
* This software falls under the GNU general public license and comes WITHOUT
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
* If you don't have this file, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******************************************************************************/

#include <numerix/rational.hpp>
#include <algebramix/matrix.hpp>
using namespace mmx;

void
pivot_test () {
  integer* o= mmx_new<integer> (400);
  integer* t= o;
  for (nat i = 0; i < 400; i++) {
    *t = integer (i+1);
    t++;
  }
  matrix<integer> O (o, 20, 20, format<integer> ());
  mmout << "O =\n" << O << "\n";
  O= row_echelon (O);
  mmout << "O =\n" << O << "\n";

  integer* m= mmx_new<integer> (400);
  integer* n= m;
  for (nat i = 0; i < 400; i++) {
    *n = integer (i+1);
    n++;
  }
  matrix<integer> M (m,20,20,format<integer>());
  mmout << "M = \n"<< M << "\n";
  M= row_echelon (M);
  mmout << "M = \n"<< M << "\n";

  rational* a= mmx_new<rational> (400);
  rational* b= a;
  for (nat i = 0; i < 400; i++) {
    *b = rational (i+1);
    b++;
  }
  matrix<rational> A (a,20,20,format<rational>());
  mmout << "rank 2 -> " << rank(A) <<"\n";
  mmout << "facto_rank 2 -> " << rank (A)<<"\n";
  mmout << "det 0 -> " << det (A)<<"\n";

  matrix<rational> B (rational(0), 5, 3);
  B(0,0)= 1; B(0,1)= 2;
  B(1,0)= 7; B(1,1)= 3;
  B(2,0)= 6; B(2,1)= 5;
  B(4,2)= 11;
  B= transpose (B);
  mmout << "B= " << B << "\n";
  mmout << "ker(B)= " << kernel (B) << "\n";
  mmout << "B * ker(B)= " << B * kernel (B) << "\n";
}

int
main() {
  try {
    pivot_test ();
  }
  catch (exception& e) {
    mmout << "ERROR in pivot_test: " << e << "\n";
    return -1;
  }
  return 0;
}
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines