[Home] [News] [API] [Example usage] [FAQ] [Roadmap] [Download] [Contact]

Simple maths

   1: /***************************************************************************
   2:                           main.cpp  -  description
   3:                              -------------------
   4:     begin                : Sun Feb 17 18:31:02 EST 2002
   5:     copyright            : (C) 2002 by Rudolph Pienaar
   6:     email                : pienaar@bme.ri.ccf.org
   7:  ***************************************************************************/
   9: 
  10: /***************************************************************************
  11:  *                                                                         *
  12:  *   This program is free software; you can redistribute it and/or modify  *
  13:  *   it under the terms of the GNU General Public License as published by  *
  14:  *   the Free Software Foundation; either version 2 of the License, or     *
  15:  *   (at your option) any later version.                                   *
  16:  *                                                                         *
  17:  ***************************************************************************/
  19: 
  20: #ifdef HAVE_CONFIG_H 
  21: #include <config.h> 
  22: #endif 
  23: 
  24: #include <iostream.h> 
  25: #include <stdlib.h> 
  26: 
  27: #include "../CMatrix/cmatrix.h" 
  28: 
  29: int main(int argc, char *argv[])
  30: {
  31: 
  32:     double      pf_dataSet1[] = {
  33:         -1.2,   1.4,    4.3,    6.7,
  34:         -5.4,   4.2,    8.5,    9.0
  35:     };
  36: 
  37:     CMatrix     M_A("I", 5);
  38:     CMatrix     M_B(5, 5);
  39: 
  40:     M_A.print("M_A");
  41:     M_B = M_A.inverse();
  42:     M_B.print("inverse(M_A)");
  43:     cout << "det(M_A)\t\t\t= " << M_A.determinant() << endl;
  44:     cout << "det(M_B) (inv(det(M_m)))\t= " << M_B.determinant() << endl;
  45: 
  46:     M_A.randomize(1, 100);
  47:     M_A.print("\nM_A (randomized)");
  48:     M_B = M_A.inverse();
  49:     ios::fmtflags format = ios::scientific;
  50:     int	precision = 8;
  51:     int width	  = 16;
  52:     M_B.print("inverse(M_A)", precision, width, format);
  53:     cout << "det(M_A)\t\t\t= " << M_A.determinant() << endl;
  54:     cout << "det(M_B) (inv(det(M_B)))\t= " << M_B.determinant() << endl << endl;
  55: 
  56:     CMatrix     M_C(2, 4, pf_dataSet1);
  57:                 // Create a matrix, M_C, of size 2x4
  58:                 //      with values read from float array
  59:                 //      pf_dataSet1
  60:     CMatrix	M_D(4, 2, pf_dataSet1);
  61:                 // Create a matrix, M_D, of size 4x2
  62:                 //      with values read from float array
  63:                 //      pf_dataSet1
  64: 
  65:     M_C.print("Matrix C");
  66:     M_D.print("Matrix D");
  67: 
  68:     (M_C * M_D).print("C * D");
  69:     (M_D * M_C).print("D * C");
  70: 
  71:     return EXIT_SUCCESS;
  72: }
  73: