tmtg.cc
Go to the documentation of this file.
00001 
00002 //#define WANT_STREAM
00003 
00004 #define WANT_MATH                   // for sqrt
00005 
00006 #include "include.h"
00007 
00008 #include "newmatap.h"
00009 
00010 #include "tmt.h"
00011 
00012 #ifdef use_namespace
00013 using namespace NEWMAT;
00014 #endif
00015 
00016 
00017 
00018 void trymatg()
00019 {
00020 //   cout << "\nSixteenth test of Matrix package\n";
00021 //   cout << "\n";
00022    Tracer et("Sixteenth test of Matrix package");
00023    Tracer::PrintTrace();
00024 
00025    int i,j;
00026    Matrix M(4,7);
00027    for (i=1; i<=4; i++) for (j=1; j<=7; j++) M(i,j) = 100 * i + j;
00028    ColumnVector CV = M.AsColumn();
00029    {
00030       Tracer et1("Stage 1");
00031       RowVector test(7);
00032       test(1) = SumSquare(M);
00033       test(2) = SumSquare(CV);
00034       test(3) = SumSquare(CV.t());
00035       test(4) = SumSquare(CV.AsDiagonal());
00036       test(5) = SumSquare(M.AsColumn());
00037       test(6) = Matrix(CV.t()*CV)(1,1);
00038       test(7) = (CV.t()*CV).AsScalar();
00039       test = test - 2156560.0; Print(test);
00040    }
00041 
00042    UpperTriangularMatrix U(6);
00043    for (i=1; i<=6; i++) for (j=i; j<=6; j++) U(i,j) = i + (i-j) * (i-j);
00044    M = U; DiagonalMatrix D; D << U;
00045    LowerTriangularMatrix L = U.t(); SymmetricMatrix S; S << (L+U)/2.0;
00046    {
00047       Tracer et1("Stage 2");
00048       RowVector test(6);
00049       test(1) = U.Trace();
00050       test(2) = L.Trace();
00051       test(3) = D.Trace();
00052       test(4) = S.Trace();
00053       test(5) = M.Trace();
00054       test(6) = ((L+U)/2.0).Trace();
00055       test = test - 21; Print(test);
00056       test(1) = LogDeterminant(U).Value();
00057       test(2) = LogDeterminant(L).Value();
00058       test(3) = LogDeterminant(D).Value();
00059       test(4) = LogDeterminant(D).Value();
00060       test(5) = LogDeterminant((L+D)/2.0).Value();
00061       test(6) = Determinant((L+D)/2.0);
00062       test = test - 720; Clean(test,0.000000001); Print(test);
00063    }
00064 
00065    {
00066       Tracer et1("Stage 3");
00067       S << L*U; M = S;
00068       RowVector test(8);
00069       test(1) = LogDeterminant(S).Value();
00070       test(2) = LogDeterminant(M).Value();
00071       test(3) = LogDeterminant(L*U).Value();
00072       test(4) = LogDeterminant(Matrix(L*L)).Value();
00073       test(5) = Determinant(S);
00074       test(6) = Determinant(M);
00075       test(7) = Determinant(L*U);
00076       test(8) = Determinant(Matrix(L*L));
00077       test = test - 720.0 * 720.0; Clean(test,0.00000001); Print(test);
00078    }
00079 
00080    {
00081       Tracer et1("Stage 4");
00082       M = S * S;
00083       Matrix SX = S;
00084       RowVector test(3);
00085       test(1) = SumSquare(S);
00086       test(2) = SumSquare(SX);
00087       test(3) = Trace(M);
00088                 test = test - 3925961.0; Print(test);
00089    }
00090    {
00091       Tracer et1("Stage 5");
00092       SymmetricMatrix SM(10), SN(10);
00093       Real S = 0.0;
00094       for (i=1; i<=10; i++) for (j=i; j<=10; j++)
00095       {
00096          SM(i,j) = 1.5 * i - j; SN(i,j) = SM(i,j) * SM(i,j);
00097          if (SM(i,j) < 0.0)   SN(i,j) = - SN(i,j);
00098          S += SN(i,j) * ((i==j) ? 1.0 : 2.0);
00099       }
00100       Matrix M = SM, N = SN; RowVector test(4);
00101       test(1) = SumAbsoluteValue(SN);
00102       test(2) = SumAbsoluteValue(-SN);
00103       test(3) = SumAbsoluteValue(N);
00104       test(4) = SumAbsoluteValue(-N);
00105       test = test - 1168.75; Print(test);
00106       test(1) = Sum(SN);
00107       test(2) = -Sum(-SN);
00108       test(3) = Sum(N);
00109       test(4) = -Sum(-N);
00110       test = test - S; Print(test);
00111       test(1) = MaximumAbsoluteValue(SM);
00112       test(2) = MaximumAbsoluteValue(-SM);
00113       test(3) = MaximumAbsoluteValue(M);
00114       test(4) = MaximumAbsoluteValue(-M);
00115       test = test - 8.5; Print(test);
00116    }
00117    {
00118       Tracer et1("Stage 6");
00119       Matrix M(15,20); Real value = 0.0;
00120       for (i=1; i<=15; i++) { for (j=1; j<=20; j++) M(i,j) = 1.5 * i - j; }
00121       for (i=1; i<=20; i++)
00122       { Real v = SumAbsoluteValue(M.Column(i)); if (value<v) value = v; }
00123       RowVector test(3);
00124       test(1) = value;
00125       test(2) = Norm1(M);
00126       test(3) = NormInfinity(M.t());
00127       test = test - 165; Print(test);
00128       test.ReSize(5);
00129       ColumnVector CV = M.AsColumn(); M = CV.t();
00130       test(1) = Norm1(CV.t());
00131       test(2) = MaximumAbsoluteValue(M);
00132       test(3) = NormInfinity(CV);
00133       test(4) = Norm1(M);
00134       test(5) = NormInfinity(M.t());
00135       test = test - 21.5; Print(test);
00136    }
00137    {
00138       Tracer et1("Stage 7");
00139       Matrix M(15,20);
00140       for (i=1; i<=15; i++) { for (j=1; j<=20; j++) M(i,j) = 2.5 * i - j; }
00141       SymmetricMatrix SM; SM << M * M.t();
00142       ColumnVector test(6);
00143       test(1) = sqrt(SumSquare(M)) - NormFrobenius(M);
00144       Real a = sqrt(SumSquare(SM));
00145       test(2) = NormFrobenius(M * M.t()) - a;
00146       test(3) = SM.NormFrobenius() - a;
00147       test(4) = (M * M.t()).NormFrobenius() - a;
00148       test(5) = NormFrobenius(SM) - a;
00149       test(6) = Trace(SM) - M.SumSquare();
00150       Clean(test, 0.00000001); Print(test);
00151   }
00152 
00153 //   cout << "\nEnd of Sixteenth test\n";
00154 }


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