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

  1. #include <LEDA/vector.h>
  2. #include <LEDA/matrix.h>
  3. #include <LEDA/list.h>
  4.  
  5. declare(list,vector)
  6.  
  7.  
  8. main()
  9.  
  10.   int d = read_int("dimension = ");
  11.  
  12.   matrix       A(d,d);
  13.   vector       b(d);
  14.   vector       x(d);
  15.  
  16.   list(vector) B;  // List of b-vectors
  17.   list(vector) X;  // List of x-vectors
  18.  
  19.   printf("give (%d x %d) - matrix A:\n",d,d);
  20.  
  21.   cin >> A;
  22.  
  23.   cout << "A = \n";
  24.   cout << A << "\n";
  25.   newline;
  26.  
  27.   cout << "A.trans() = \n";
  28.   cout << A.trans() << "\n";
  29.   newline;
  30.  
  31.  
  32.   cout << "A.inv() = \n";
  33.   cout << A.inv() << "\n";
  34.   newline;
  35.  
  36.   cout << "A*A.inv() = \n";
  37.   cout << A*A.inv() << "\n";
  38.   newline;
  39.   
  40.  
  41.   cout << "We solve the system of linear equations A*x = b.\n";
  42.   cout << "Give a list of vectors b (terminated by ctrl-d):\n";
  43.  
  44.   while (cin >> b) B.append(b);
  45.   newline;
  46.  
  47.   B.print("b's = ",'\n');
  48.   newline;
  49.   newline;
  50.  
  51.   forall(b,B)  X.append(A.solve(b));
  52.   
  53.   X.print("x's = ",'\n');
  54.   newline;
  55.   newline;
  56.  
  57.  
  58.   cout << "A*x's = \n";
  59.   forall(x,X) cout << A*x << "\n";
  60.   newline;
  61.  
  62. }
  63.