home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / prog / basic / matrix1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  931 b   |  57 lines

  1. #include <LEDA/vector.h>
  2. #include <LEDA/matrix.h>
  3.  
  4. main()
  5.  
  6.   int d = read_int("dimension = ");
  7.  
  8.   matrix       A(d,d);
  9.   matrix       I(d,d);
  10.   double       det;
  11.  
  12.  
  13.   init_random();
  14.  
  15.   for(int i=0;i<d;i++)
  16.     for(int j=0;j<d;j++)
  17.       A(i,j) = double(random(-1000,1000))/100;
  18.  
  19.   float T = used_time();
  20.  
  21.  
  22.   cout << "A.inv():  ";
  23.   cout.flush();
  24.   I =  A.inv();
  25.   cout << string("%5.2f sec\n",used_time(T));
  26.  
  27.   cout << "A.det():  ";
  28.   cout.flush();
  29.   det = A.det();
  30.   cout << string("%5.2f sec \n",used_time(T));
  31.   newline;
  32.  
  33. /*
  34.   cout << "A*A.inv() = \n" << A*I << "\n";
  35.   newline;
  36. */
  37.  
  38.   while (Yes("A.solve(v) ? "))
  39.   {
  40.     vector v(d), x(d), y(d);
  41.  
  42.     for(int i=0;i<d;i++) v[i] = double(random(-1000,1000))/100;
  43.     
  44.     used_time(T);
  45.     x = A.solve(v);
  46.     cout << string("time for solve:  %5.2f \n",used_time(T));
  47.     newline;
  48.  
  49.     cout << "v   = " << v   << "\n";
  50.     cout << "A*x = " << A*x << "\n";
  51.     newline;
  52.   }
  53.  
  54.  
  55. }
  56.