home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / DRMATRIX.ZIP / EXAMPLES / DRMDEMO / DRMDEMO.CPP next >
Encoding:
C/C++ Source or Header  |  1997-01-01  |  3.1 KB  |  134 lines

  1. #include <iostream.h>
  2. #include <conio.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5.  
  6. #include "drmatrix.hpp"
  7.  
  8. void vector_arith();
  9. void matrix_arith();
  10. void matrix_prop();
  11.  
  12. int main()
  13. {
  14.     int choice;
  15.     char a[10];
  16.     do {
  17.         clrscr();
  18.         cout << "Please choose an option:\n\n"
  19.              << "1. Matrix Arithmetic\n"
  20.              << "2. Matrix Properties\n"
  21.              << "3. Vector Arithmetic\n"
  22.              << "0. Exit\n";
  23.         cin >> choice;
  24.         switch(choice)
  25.         {
  26.             case 0:                    break;
  27.             case 1: matrix_arith(); break;
  28.             case 2: matrix_prop();  break;
  29.             case 3: vector_arith(); break;
  30.             default: cin.getline(a,10); break;
  31.         }
  32.     } while(choice!=0);
  33.     return 0;
  34. }
  35.  
  36. void vector_arith()
  37. {
  38.     float r;
  39.     Vector<float> b(3,V_HORIZ);
  40.     clrscr();
  41.     cout << "Please enter the value of b, a 3-vector over R:" << endl;
  42.     cin >> b;
  43.     cout << "\nPlease enter the value of r, a real scalar:" << endl;
  44.     cin >> r;
  45.     clrscr();
  46.     cout << "b:\n" << b << endl << endl << "b Transpose:\n" << b.T()
  47.          << "\n\nr*b:\n" << r*b << "\nb+b:\n" << b+b << "\nb*bT:\n"
  48.          << b * b.T() << "\n|b|:\n" << b.abs() << "\nPress any key...\n";
  49.     getch();
  50. }
  51.  
  52. void matrix_arith()
  53. {
  54.     int rows,cols;
  55.     clrscr();
  56.     cout << "Please select a matrix size (e.g. 2 3 for 2 rows, 3 columns):\n";
  57.     cin  >> rows >> cols;
  58.     Matrix<float> m(rows,cols);
  59.     cout << "Please enter a " << rows << 'x' << cols << " matrix:\n";
  60.     cin  >> m;
  61.     clrscr();
  62.     cout << "M:\n" << m << "\nM Transpose:\n" << m.T()
  63.          << "\n\nPress any key...\n";
  64.     getch();
  65.     clrscr();
  66.     cout << "3*M:\n" << 3*m << "\nM+M:\n" << m+m
  67.          << "\n\nPress any key...";
  68.     getch();
  69.     clrscr();
  70.     cout << "M * M Transpose:\n" << m*m.T();
  71.     if(m.square())
  72.         cout << "\nTr{M} (Sum of diagonal):\n" << m.tr() << "\n\n|M|:\n"
  73.              << m.det();
  74.     cout << "\n\nPress any key to continue...";
  75.     getch();
  76.     clrscr();
  77.     cout << "Stepped matrix equivalent to M:\n" << m.step();
  78.     cout << "\n\nM's equivalent canonized matrix:\n" << m.canon();
  79.     cout << "\n\nRank{M}:\n" << m.rank()
  80.          << "\n\nPress any key to continue...";
  81.     if(m.reg())
  82.     {
  83.         Matrix<float> minv = m.inv();
  84.         getch();
  85.         clrscr();
  86.         cout << "Regular (reversible) matrix.\n\n"
  87.              << "M's inverse matrix:\n"
  88.              << minv
  89.              << "\n\nPress any key to continue...";
  90.     }
  91.     getch();
  92. }
  93.  
  94. void matrix_prop()
  95. {
  96.     Matrix<float> m(4,4);
  97.     clrscr();
  98.     cout << "Please enter a 4x4 matrix:\n";
  99.     cin  >> m;
  100.     cout << "\n\n";
  101.     if(m.square())
  102.         cout << "Square matrix\n";
  103.     else
  104.         cout << "Non-square matrix\n";
  105.     if(m.diag())
  106.         cout << "Diagonal matrix\n";
  107.     else
  108.         cout << "Non-diagonal matrix\n";
  109.     if(m.iden())
  110.         cout << "Identity matrix\n";
  111.     if(m.scalar())
  112.         cout << "Scalar matrix\n";
  113.     else
  114.         cout << "Non-scalar matrix\n";
  115.     if(m.sym())
  116.         cout << "Symmetric matrix\n";
  117.     else
  118.         cout << "Not a symmetric matrix\n";
  119.     if(m.antisym())
  120.         cout << "Antisymmetric matrix\n";
  121.     else
  122.         cout << "Not an antisymmetric matrix\n";
  123.     if(m.stepped())
  124.         cout << "Stepped matrix\n";
  125.     else
  126.         cout << "Not a stepped matrix\n";
  127.     if(m.reg())
  128.         cout << "Regular (reversible) matrix\n";
  129.     else
  130.         cout << "Singular (non-reversible) matrix\n";
  131.     cout << "\nPress any key...";
  132.     getch();
  133. }
  134.