home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sources / misc / 4255 / tmt5.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-11  |  1.7 KB  |  68 lines

  1.  
  2. //#define WANT_STREAM
  3.  
  4.  
  5. #include "include.h"
  6.  
  7. #include "newmat.h"
  8.  
  9.  
  10. /**************************** test program ******************************/
  11.  
  12. void Print(const Matrix& X);
  13. void Print(const UpperTriangularMatrix& X);
  14. void Print(const DiagonalMatrix& X);
  15. void Print(const SymmetricMatrix& X);
  16. void Print(const LowerTriangularMatrix& X);
  17.  
  18. void trymat5()
  19. {
  20. //   cout << "\nFifth test of Matrix package\n";
  21.    Tracer et("Fifth test of Matrix package");
  22.    Exception::PrintTrace(TRUE);
  23.  
  24.    int i,j;
  25.  
  26.    Matrix A(5,6);
  27.    for (i=1;i<=5;i++) for (j=1;j<=6;j++) A(i,j)=1+i*j+i*i+j*j;
  28.    ColumnVector CV(6);
  29.    for (i=1;i<=6;i++) CV(i)=i*i+3;
  30.    ColumnVector CV2(5); for (i=1;i<=5;i++) CV2(i)=1.0;
  31.    ColumnVector CV1=CV;
  32.  
  33.    {
  34.       CV=A*CV;
  35.       RowVector RV=CV.t(); // RowVector RV; RV=CV.t();
  36.       RV=RV-1.0;
  37.       CV=(RV*A).t()+A.t()*CV2; CV1=(A.t()*A)*CV1 - CV;
  38.       Print(CV1);
  39.    }
  40.  
  41.    CV1.ReDimension(6);
  42.    CV2.ReDimension(6);
  43.    CV.ReDimension(6);
  44.    for (i=1;i<=6;i++) { CV1(i)=i*3+1; CV2(i)=10-i; CV(i)=11+i*2; }
  45.    ColumnVector CX=CV2-CV; { CX=CX+CV1; Print(CX); }
  46.    Print(ColumnVector(CV1+CV2-CV));
  47.    RowVector RV=CV.t(); RowVector RV1=CV1.t();
  48.    RowVector R=RV-RV1; Print(RowVector(R-CV2.t()));
  49.  
  50. // test loading of list
  51.  
  52.    RV.ReDimension(10);
  53.    for (i=1;i<=10;i++) RV(i) = i*i;
  54.    RV1.ReDimension(10);
  55.    RV1 << 1 << 4 << 9 << 16 << 25 << 36 << 49 << 64 << 81 << 100; // << 121;
  56.    Print(RowVector(RV-RV1));
  57.    et.ReName("Fifth test of Matrix package - at end");
  58.    Matrix X(2,3);
  59.    X << 11 << 12 << 13
  60.      << 21 << 22 << 23;
  61.    X(1,1) -= 11; X(1,2) -= 12; X(1,3) -= 13;
  62.    X(2,1) -= 21; X(2,2) -= 22; X(2,3) -= 23;
  63.    Print(X);
  64. //   BandMatrix BM(7,2,2); BM << 23;
  65.  
  66. //   cout << "\nEnd of fifth test\n";
  67. }
  68.