tmtb.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00006 
00007 
00008 //#define WANT_STREAM
00009 
00010 #include "include.h"
00011 
00012 #include "newmat.h"
00013 
00014 #include "tmt.h"
00015 
00016 #ifdef use_namespace
00017 using namespace NEWMAT;
00018 #endif
00019 
00020 
00021 /**************************** test program ******************************/
00022 
00023 // make sure matrices work as members of a class
00024 
00025 class TestClass
00026 {
00027    Matrix A;
00028    Matrix B;
00029 public:
00030    TestClass();
00031    ReturnMatrix Sum();
00032 };
00033 
00034 TestClass::TestClass() : A(2,3)
00035 {
00036    B.ReSize(2,3);
00037    A << 1 << 4
00038      << 4 << 1
00039      << 2 << 9;
00040    B << 8 << 5
00041      << 5 << 8
00042      << 7 << 0;
00043 }
00044 
00045 ReturnMatrix TestClass::Sum() { return Matrix(A + B).ForReturn(); }
00046 
00047 
00048 
00049 void trymatb()
00050 {
00051 //   cout << "\nEleventh test of Matrix package\n";
00052    Tracer et("Eleventh test of Matrix package");
00053    Tracer::PrintTrace();
00054    int i; int j;
00055    RowVector RV; RV.ReSize(10);
00056    {
00057       Tracer et1("Stage 1");
00058       for (i=1;i<=10;i++) RV(i)=i*i-3;
00059       Matrix X(1,1); X(1,1) = .25;
00060       Print(RowVector(X.i() * RV - RV / .25));
00061 //      Print(RowVector(X.i() * Matrix(RV) - RV / .25)); // != zortech, AT&T
00062       Print(RowVector(X.i() * RV - RV / .25));
00063    }
00064    LowerTriangularMatrix L(5); UpperTriangularMatrix U(5);
00065    for (i=1; i<=5; i++) for (j=1; j<=i; j++)
00066    { L(i,j) = i*i + j -2.0; U(j,i) = i*i*j+3; }
00067    DiagonalMatrix D(5);
00068    for (i=1; i<=5; i++) D(i,i) = i*i + i + 2;
00069    Matrix M1 = -L; Matrix M2 = L-U; Matrix M3 = U*3; Matrix M4 = U-L;
00070    Matrix M5 = M1 - D; M1 = D * (-3) - M3;
00071    {
00072       Tracer et1("Stage 2");
00073       Print(Matrix((M2-M4*2)+M5*3-M1));
00074       M1 = L.t(); Print(Matrix(M1.t()-L));
00075       M1 = U.t(); Print(Matrix(M1.t()-U));
00076    }
00077    {
00078       Tracer et1("Stage 3");
00079       SymmetricMatrix S(5);
00080       for (i=1; i<=5; i++) for (j=1; j<=i; j++) S(i,j) = i*j+i-j+5;
00081       M2 = S.i() * M4; M1 = S; M3=M1*M2-M4; Clean(M3,0.00000001); Print(M3);
00082       SymmetricMatrix T(5);
00083       for (i=1; i<=5; i++) for (j=1; j<=i; j++) T(i,j) = i*i*j*j+i-j+5-i*j;
00084       M1 = S.i() * T; M1 = S * M1; M1 = M1-T; Clean(M1,0.00000001); Print(M1);
00085       ColumnVector CV(5); for (i=1; i<=5; i++) CV(i) = i*i*i+10;
00086       M1 = CV * RV;
00087    }
00088    {
00089       Tracer et1("Stage 4");
00090       M4.ReSize(5,10);
00091       for (i=1; i<=5; i++) for (j=1; j<=10; j++) M4(i,j) = (i*i*i+10)*(j*j-3);
00092       Print(Matrix(M1-M4));
00093       M1 = L.t(); M2 = U.t(); M3 = L+U; Print(Matrix(M1-M3.t()+M2));
00094    }
00095 //   UpperTriangularMatrix U2((const UpperTriangularMatrix&)U); // != zortech
00096    UpperTriangularMatrix U2((UpperTriangularMatrix&)U);
00097    {
00098       Tracer et1("Stage 5");
00099       Print(Matrix(U2-U));
00100       M2.ReSize(10,10);
00101       for (i=1; i<=10; i++) for (j=1; j<=10; j++) M2(i,j) = (i*i*i+10)*(j*j-3);
00102       D << M2; L << M2; U << M2;               // check copy into
00103       Print( Matrix( (D+M2)-(L+U) ) );
00104    }
00105    {
00106       Tracer et1("Stage 6");
00107       M1.ReSize(6,10);
00108       for (i=1; i<=6; i++) for (j=1; j<=10; j++)  M1(i,j) = 100*i + j;
00109       M2 = M1.SubMatrix(3,5,4,7);  M3.ReSize(3,4);
00110       for (i=3; i<=5; i++) for (j=4; j<=7; j++)   M3(i-2,j-3) = 100*i + j;
00111       Print(Matrix(M2-M3));
00112    }
00113    int a1,a2,a3,a4;
00114    {
00115       Tracer et1("Stage 7");
00116       int a1,a2,a3,a4;
00117       a1=4; a2=9; a3=4; a4=7;
00118       U.ReSize(10);
00119       for (i=1; i<=10; i++) for (j=i; j<=10; j++)  U(i,j) = 100*i + j;
00120       M2 = U.SubMatrix(a1,a2,a3,a4);
00121       M3.ReSize(a2-a1+1,a4-a3+1); M3=0.0;
00122       for (i=a1; i<=a2; i++) for (j=(i>a3) ? i : a3; j<=a4; j++)
00123          M3(i-a1+1,j-a3+1) = 100*i + j;
00124       Print(Matrix(M2-M3));
00125    }
00126    {
00127       Tracer et1("Stage 8");
00128       a1=3; a2=9; a3=2; a4=7;
00129       U.ReSize(10);
00130       for (i=1; i<=10; i++) for (j=i; j<=10; j++)  U(i,j) = 100*i + j;
00131       M2 = U.SubMatrix(a1,a2,a3,a4);
00132       M3.ReSize(a2-a1+1,a4-a3+1); M3=0.0;
00133       for (i=a1; i<=a2; i++) for (j=(i>a3) ? i : a3; j<=a4; j++)
00134          M3(i-a1+1,j-a3+1) = 100*i + j;
00135       Print(Matrix(M2-M3));
00136    }
00137    {
00138       Tracer et1("Stage 9");
00139       a1=4; a2=6; a3=2; a4=5;
00140       U.ReSize(10);
00141       for (i=1; i<=10; i++) for (j=i; j<=10; j++)  U(i,j) = 100*i + j;
00142       M2 = U.SubMatrix(a1,a2,a3,a4);
00143       M3.ReSize(a2-a1+1,a4-a3+1); M3=0.0;
00144       for (i=a1; i<=a2; i++) for (j=(i>a3) ? i : a3; j<=a4; j++)
00145          M3(i-a1+1,j-a3+1) = 100*i + j;
00146       Print(Matrix(M2-M3));
00147    }
00148 
00149    {
00150       Tracer et1("Stage 10");
00151       TestClass TC;
00152       Matrix M = TC.Sum() - 9;
00153       Print(M);
00154    }
00155 
00156 
00157 //   cout << "\nEnd of eleventh test\n";
00158 }
00159 
00160 
00161 


kni
Author(s): Neuronics AG (see AUTHORS.txt); ROS wrapper by Martin Günther
autogenerated on Mon Oct 6 2014 10:45:33