tmtc.cc
Go to the documentation of this file.
00001 
00002 //#define WANT_STREAM
00003 
00004 
00005 #include "include.h"
00006 #include "newmat.h"
00007 
00008 #include "tmt.h"
00009 
00010 #ifdef use_namespace
00011 using namespace NEWMAT;
00012 #endif
00013 
00014 
00015 
00016 
00017 void trymatc()
00018 {
00019 //   cout << "\nTwelfth test of Matrix package\n";
00020    Tracer et("Twelfth test of Matrix package");
00021    Tracer::PrintTrace();
00022    DiagonalMatrix D(15); D=1.5;
00023    Matrix A(15,15);
00024    int i,j;
00025    for (i=1;i<=15;i++) for (j=1;j<=15;j++) A(i,j)=i*i+j-150;
00026    { A = A + D; }
00027    ColumnVector B(15);
00028    for (i=1;i<=15;i++) B(i)=i+i*i-150.0;
00029    {
00030       Tracer et1("Stage 1");
00031       ColumnVector B1=B;
00032       B=(A*2.0).i() * B1;
00033       Matrix X = A*B-B1/2.0;
00034       Clean(X, 0.000000001); Print(X);
00035       A.ReSize(3,5);
00036       for (i=1; i<=3; i++) for (j=1; j<=5; j++) A(i,j) = i+100*j;
00037 
00038       B = A.AsColumn()+10000;
00039       RowVector R = (A+10000).AsColumn().t();
00040       Print( RowVector(R-B.t()) );
00041    }
00042 
00043    {
00044       Tracer et1("Stage 2");
00045       B = A.AsColumn()+10000;
00046       Matrix XR = (A+10000).AsMatrix(15,1).t();
00047       Print( RowVector(XR-B.t()) );
00048    }
00049 
00050    {
00051       Tracer et1("Stage 3");
00052       B = (A.AsMatrix(15,1)+A.AsColumn())/2.0+10000;
00053       Matrix MR = (A+10000).AsColumn().t();
00054       Print( RowVector(MR-B.t()) );
00055 
00056       B = (A.AsMatrix(15,1)+A.AsColumn())/2.0;
00057       MR = A.AsColumn().t();
00058       Print( RowVector(MR-B.t()) );
00059    }
00060 
00061    {
00062       Tracer et1("Stage 4");
00063       B = (A.AsMatrix(15,1)+A.AsColumn())/2.0;
00064       RowVector R = A.AsColumn().t();
00065       Print( RowVector(R-B.t()) );
00066    }
00067 
00068    {
00069       Tracer et1("Stage 5");
00070       RowVector R = (A.AsColumn()-5000).t();
00071       B = ((R.t()+10000) - A.AsColumn())-5000;
00072       Print( RowVector(B.t()) );
00073    }
00074 
00075    {
00076       Tracer et1("Stage 6");
00077       B = A.AsColumn(); ColumnVector B1 = (A+10000).AsColumn() - 10000;
00078       Print(ColumnVector(B1-B));
00079    }
00080 
00081    {
00082       Tracer et1("Stage 7");
00083       Matrix X = B.AsMatrix(3,5); Print(Matrix(X-A));
00084       for (i=1; i<=3; i++) for (j=1; j<=5; j++) B(5*(i-1)+j) -= i+100*j;
00085       Print(B);
00086    }
00087 
00088    {
00089       Tracer et1("Stage 8");
00090       A.ReSize(7,7); D.ReSize(7);
00091       for (i=1; i<=7; i++) for (j=1; j<=7; j++) A(i,j) = i*j*j;
00092       for (i=1; i<=7; i++) D(i,i) = i;
00093       UpperTriangularMatrix U; U << A;
00094       Matrix X = A; for (i=1; i<=7; i++) X(i,i) = i;
00095       A.Inject(D); Print(Matrix(X-A));
00096       X = U; U.Inject(D); A = U; for (i=1; i<=7; i++) X(i,i) = i;
00097       Print(Matrix(X-A));
00098    }
00099 
00100    {
00101       Tracer et1("Stage 9");
00102       A.ReSize(7,5);
00103       for (i=1; i<=7; i++) for (j=1; j<=5; j++) A(i,j) = i+100*j;
00104       Matrix Y = A; Y = Y - ((const Matrix&)A); Print(Y);
00105       Matrix X = A; // X.Release();
00106       Y = A; Y = ((const Matrix&)X) - A; Print(Y); Y = 0.0;
00107       Y = ((const Matrix&)X) - ((const Matrix&)A); Print(Y);
00108    }
00109 
00110    {
00111       Tracer et1("Stage 10");
00112       // some tests on submatrices
00113       UpperTriangularMatrix U(20);
00114       for (i=1; i<=20; i++) for (j=i; j<=20; j++) U(i,j)=100 * i + j;
00115       UpperTriangularMatrix V = U.SymSubMatrix(1,5);
00116       UpperTriangularMatrix U1 = U;
00117       U1.SubMatrix(4,8,5,9) /= 2;
00118       U1.SubMatrix(4,8,5,9) += 388 * V;
00119       U1.SubMatrix(4,8,5,9) *= 2;
00120       U1.SubMatrix(4,8,5,9) += V;
00121       U1 -= U; UpperTriangularMatrix U2 = U1;
00122       U1 << U1.SubMatrix(4,8,5,9);
00123       U2.SubMatrix(4,8,5,9) -= U1; Print(U2);
00124       U1 -= (777*V); Print(U1);
00125 
00126       U1 = U; U1.SubMatrix(4,8,5,9) -= U.SymSubMatrix(1,5);
00127       U1 -= U;  U2 = U1; U1 << U1.SubMatrix(4,8,5,9);
00128       U2.SubMatrix(4,8,5,9) -= U1; Print(U2);
00129       U1 += V; Print(U1);
00130 
00131       U1 = U;
00132       U1.SubMatrix(3,10,15,19) += 29;
00133       U1 -= U;
00134       Matrix X = U1.SubMatrix(3,10,15,19); X -= 29; Print(X);
00135       U1.SubMatrix(3,10,15,19) *= 0; Print(U1);
00136 
00137       LowerTriangularMatrix L = U.t();
00138       LowerTriangularMatrix M = L.SymSubMatrix(1,5);
00139       LowerTriangularMatrix L1 = L;
00140       L1.SubMatrix(5,9,4,8) /= 2;
00141       L1.SubMatrix(5,9,4,8) += 388 * M;
00142       L1.SubMatrix(5,9,4,8) *= 2;
00143       L1.SubMatrix(5,9,4,8) += M;
00144       L1 -= L; LowerTriangularMatrix L2 = L1;
00145       L1 << L1.SubMatrix(5,9,4,8);
00146       L2.SubMatrix(5,9,4,8) -= L1; Print(L2);
00147       L1 -= (777*M); Print(L1);
00148 
00149       L1 = L; L1.SubMatrix(5,9,4,8) -= L.SymSubMatrix(1,5);
00150       L1 -= L; L2 =L1; L1 << L1.SubMatrix(5,9,4,8);
00151       L2.SubMatrix(5,9,4,8) -= L1; Print(L2);
00152       L1 += M; Print(L1);
00153 
00154       L1 = L;
00155       L1.SubMatrix(15,19,3,10) -= 29;
00156       L1 -= L;
00157       X = L1.SubMatrix(15,19,3,10); X += 29; Print(X);
00158       L1.SubMatrix(15,19,3,10) *= 0; Print(L1);
00159    }
00160 
00161    {
00162       Tracer et1("Stage 11");
00163       // more tests on submatrices
00164       Matrix M(20,30);
00165       for (i=1; i<=20; i++) for (j=1; j<=30; j++) M(i,j)=100 * i + j;
00166       Matrix M1 = M;
00167 
00168       for (j=1; j<=30; j++)
00169          { ColumnVector CV = 3 * M1.Column(j); M.Column(j) += CV; }
00170       for (i=1; i<=20; i++)
00171          { RowVector RV = 5 * M1.Row(i); M.Row(i) -= RV; }
00172 
00173       M += M1; Print(M);
00174  
00175    }
00176 
00177    {
00178       Tracer et1("Stage 12");
00179       // more tests on Release
00180       Matrix M(20,30);
00181       for (i=1; i<=20; i++) for (j=1; j<=30; j++) M(i,j)=100 * i + j;
00182       Matrix M1 = M;
00183       M.Release();
00184       Matrix M2 = M;
00185       Matrix X = M;   Print(X);
00186       X = M1 - M2;    Print(X);
00187 
00188 #ifndef DONT_DO_NRIC
00189       nricMatrix N = M1;
00190       nricMatrix N1 = N;
00191       N.Release();
00192       nricMatrix N2 = N;
00193       nricMatrix Y = N;   Print(Y);
00194       Y = N1 - N2;        Print(Y);
00195 #endif
00196 
00197    }
00198 
00199 //   cout << "\nEnd of twelfth test\n";
00200 }


rl_agent
Author(s): Todd Hester
autogenerated on Thu Jun 6 2019 22:00:13