matrix.c
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:1k
开发平台:

MultiPlatform

  1. #include <LEDA/vector.h>
  2. #include <LEDA/matrix.h>
  3. #include <LEDA/list.h>
  4. main()
  5.   int d = read_int("dimension = ");
  6.   matrix       A(d,d);
  7.   vector       b(d);
  8.   vector       x(d);
  9.   list<vector> B;  // List of b-vectors
  10.   list<vector> X;  // List of x-vectors
  11.   cout << string("give (%d x %d) matrix A:",d,d) << endl;
  12.   cin >> A;
  13.   cout << "A = n";
  14.   cout << A << "n";
  15.   newline;
  16.   cout << "A.trans() = n";
  17.   cout << A.trans() << "n";
  18.   newline;
  19.   cout << "A.inv() = n";
  20.   cout << A.inv() << "n";
  21.   newline;
  22.   cout << "A*A.inv() = n";
  23.   cout << A*A.inv() << "n";
  24.   newline;
  25.   
  26.   cout << "We solve the system of linear equations A*x = b.n";
  27.   cout << "Give a list of vectors b (terminated by ctrl-d):n";
  28.   while (cin >> b) B.append(b);
  29.   newline;
  30.   B.print("b's = ",'n');
  31.   newline;
  32.   newline;
  33.   forall(b,B)  X.append(A.solve(b));
  34.   
  35.   X.print("x's = ",'n');
  36.   newline;
  37.   newline;
  38.   cout << "A*x's = n";
  39.   forall(x,X) cout << A*x << "n";
  40.   newline;
  41.  
  42.   return 0;
  43. }