tmtm.cc
Go to the documentation of this file.
00001 
00002 #define WANT_STREAM
00003 
00004 #define WANT_MATH
00005 
00006 #include "newmat.h"
00007 
00008 #include "tmt.h"
00009 
00010 #ifdef use_namespace
00011 using namespace NEWMAT;
00012 #endif
00013 
00014 
00015 
00016 // test Kronecker Product
00017 
00018 
00019 void trymatm()
00020 {
00021    Tracer et("Twenty second test of Matrix package");
00022    Tracer::PrintTrace();
00023 
00024    {
00025       Tracer et1("Stage 1");
00026 
00027 
00028       Matrix A(2,3);
00029       A << 3 << 5 << 2
00030         << 4 << 1 << 6;
00031 
00032       Matrix B(4,3);
00033       B <<  7 <<  2 <<  9
00034         <<  1 <<  3 <<  6
00035         <<  4 << 10 <<  5
00036         << 11 <<  8 << 12;
00037 
00038       Matrix C(8, 9);
00039 
00040       C.Row(1) << 21 <<  6 << 27  << 35 << 10 << 45  << 14 <<  4 << 18;
00041       C.Row(2) <<  3 <<  9 << 18  <<  5 << 15 << 30  <<  2 <<  6 << 12;
00042       C.Row(3) << 12 << 30 << 15  << 20 << 50 << 25  <<  8 << 20 << 10;
00043       C.Row(4) << 33 << 24 << 36  << 55 << 40 << 60  << 22 << 16 << 24;
00044 
00045       C.Row(5) << 28 <<  8 << 36  <<  7 <<  2 <<  9  << 42 << 12 << 54;
00046       C.Row(6) <<  4 << 12 << 24  <<  1 <<  3 <<  6  <<  6 << 18 << 36;
00047       C.Row(7) << 16 << 40 << 20  <<  4 << 10 <<  5  << 24 << 60 << 30;
00048       C.Row(8) << 44 << 32 << 48  << 11 <<  8 << 12  << 66 << 48 << 72;
00049 
00050       Matrix AB = KP(A,B) - C; Print(AB);
00051 
00052       IdentityMatrix I1(10); IdentityMatrix I2(15); I2 *= 2;
00053       DiagonalMatrix D = KP(I1, I2) - IdentityMatrix(150) * 2;
00054       Print(D);
00055    }
00056 
00057    {
00058       Tracer et1("Stage 2");
00059 
00060       UpperTriangularMatrix A(3);
00061       A << 3 << 8 << 5
00062              << 7 << 2
00063                   << 4;
00064       UpperTriangularMatrix B(4);
00065       B << 4 << 1 << 7 << 2
00066              << 3 << 9 << 8
00067                   << 1 << 5
00068                        << 6;
00069 
00070       UpperTriangularMatrix C(12);
00071 
00072       C.Row(1) <<12<< 3<<21<< 6 <<32<< 8<<56<<16 <<20<< 5<<35<<10;
00073       C.Row(2)     << 9<<27<<24 << 0<<24<<72<<64 << 0<<15<<45<<40;
00074       C.Row(3)         << 3<<15 << 0<< 0<< 8<<40 << 0<< 0<< 5<<25;
00075       C.Row(4)             <<18 << 0<< 0<< 0<<48 << 0<< 0<< 0<<30;
00076 
00077       C.Row(5)                  <<28<< 7<<49<<14 << 8<< 2<<14<< 4;
00078       C.Row(6)                      <<21<<63<<56 << 0<< 6<<18<<16;
00079       C.Row(7)                          << 7<<35 << 0<< 0<< 2<<10;
00080       C.Row(8)                              <<42 << 0<< 0<< 0<<12;
00081 
00082       C.Row(9)                                   <<16<< 4<<28<< 8;
00083       C.Row(10)                                      <<12<<36<<32;
00084       C.Row(11)                                          << 4<<20;
00085       C.Row(12)                                              <<24;
00086 
00087 
00088       UpperTriangularMatrix AB = KP(A,B) - C; Print(AB);
00089 
00090       LowerTriangularMatrix BT = B.t(); Matrix N(12,12);
00091 
00092       N.Row(1) <<12 << 0<< 0<< 0 <<32<< 0<< 0<< 0 <<20<< 0<< 0<< 0;
00093       N.Row(2) << 3 << 9<< 0<< 0 << 8<<24<< 0<< 0 << 5<<15<< 0<< 0;
00094       N.Row(3) <<21 <<27<< 3<< 0 <<56<<72<< 8<< 0 <<35<<45<< 5<< 0;
00095       N.Row(4) << 6 <<24<<15<<18 <<16<<64<<40<<48 <<10<<40<<25<<30;
00096 
00097       N.Row(5) << 0 << 0<< 0<< 0 <<28<< 0<< 0<< 0 << 8<< 0<< 0<< 0;
00098       N.Row(6) << 0 << 0<< 0<< 0 << 7<<21<< 0<< 0 << 2<< 6<< 0<< 0;
00099       N.Row(7) << 0 << 0<< 0<< 0 <<49<<63<< 7<< 0 <<14<<18<< 2<< 0;
00100       N.Row(8) << 0 << 0<< 0<< 0 <<14<<56<<35<<42 << 4<<16<<10<<12;
00101 
00102       N.Row(9) << 0 << 0<< 0<< 0 << 0<< 0<< 0<< 0 <<16<< 0<< 0<< 0;
00103       N.Row(10)<< 0 << 0<< 0<< 0 << 0<< 0<< 0<< 0 << 4<<12<< 0<< 0;
00104       N.Row(11)<< 0 << 0<< 0<< 0 << 0<< 0<< 0<< 0 <<28<<36<< 4<< 0;
00105       N.Row(12)<< 0 << 0<< 0<< 0 << 0<< 0<< 0<< 0 << 8<<32<<20<<24;
00106 
00107       Matrix N1 = KP(A, BT); N1 -= N; Print(N1);
00108       AB << KP(A, BT); AB << (AB - N); Print(AB);
00109       BT << KP(A, BT); BT << (BT - N); Print(BT);
00110 
00111       LowerTriangularMatrix AT = A.t();
00112       N1 = KP(AT, B); N1 -= N.t(); Print(N1);
00113       AB << KP(AT, B); AB << (AB - N.t()); Print(AB);
00114       BT << KP(AT, B); BT << (BT - N.t()); Print(BT);
00115    }
00116 
00117    {
00118       Tracer et1("Stage 3");
00119 
00120       BandMatrix BMA(6,2,3);
00121       BMA.Row(1) << 5.25 << 4.75 << 2.25 << 1.75;
00122       BMA.Row(2) << 1.25 << 9.75 << 4.50 << 0.25 << 1.50;
00123       BMA.Row(3) << 7.75 << 1.50 << 3.00 << 4.25 << 0.50 << 5.50;
00124       BMA.Row(4) << 2.75 << 9.00 << 8.00 << 3.25 << 3.50;
00125       BMA.Row(5) << 8.75 << 6.25 << 5.00 << 5.75;
00126       BMA.Row(6) << 3.75 << 6.75 << 6.00;
00127 
00128       Matrix A = BMA;
00129 
00130       BandMatrix BMB(4,2,1);
00131       BMB.Row(1) << 4.5 << 9.5;
00132       BMB.Row(2) << 1.5 << 6.0 << 2.0;
00133       BMB.Row(3) << 0.5 << 2.5 << 8.5 << 7.5;
00134       BMB.Row(4) << 3.0 << 4.0 << 6.5;
00135 
00136       Matrix B = BMB;
00137 
00138       BandMatrix BMC = KP(BMA, BMB);
00139       BandMatrix BMC1(24,11,15);
00140       BMC1.Inject(Matrix(KP(BMA, B)));  // not directly Band Matrix
00141       Matrix C2 = KP(A, BMB);
00142       Matrix C = KP(A, B);
00143 
00144       Matrix M = C - BMC; Print(M);
00145       M = C - BMC1; Print(M);
00146       M = C - C2; Print(M);
00147 
00148       RowVector X(4);
00149       X(1) = BMC.BandWidth().Lower() - 10;
00150       X(2) = BMC.BandWidth().Upper() - 13;
00151       X(3) = BMC1.BandWidth().Lower() - 11;
00152       X(4) = BMC1.BandWidth().Upper() - 15;
00153       Print(X);
00154 
00155       UpperTriangularMatrix UT;  UT << KP(BMA, BMB);
00156       UpperTriangularMatrix UT1; UT1 << (C - UT); Print(UT1);
00157       LowerTriangularMatrix LT;  LT << KP(BMA, BMB);
00158       LowerTriangularMatrix LT1; LT1 << (C - LT); Print(LT1);
00159    }
00160 
00161    {
00162       Tracer et1("Stage 4");
00163 
00164       SymmetricMatrix SM1(4);
00165       SM1.Row(1) << 2;
00166       SM1.Row(2) << 4 << 5;
00167       SM1.Row(3) << 9 << 2 << 1;
00168       SM1.Row(4) << 3 << 6 << 8 << 2;
00169 
00170       SymmetricMatrix SM2(3);
00171       SM2.Row(1) <<  3;
00172       SM2.Row(2) << -7 << -6;
00173       SM2.Row(3) <<  4 << -2 << -1;
00174 
00175       SymmetricMatrix SM = KP(SM1, SM2);
00176       Matrix M1 = SM1; Matrix M2 = SM2;
00177       Matrix M = KP(SM1, SM2); M -= SM; Print(M);
00178       M = KP(SM1, SM2) - SM; Print(M);
00179       M = KP(M1, SM2) - SM; Print(M);
00180       M = KP(SM1, M2) - SM; Print(M);
00181       M = KP(M1, M2); M -= SM; Print(M);
00182    }
00183 
00184    {
00185       Tracer et1("Stage 5");
00186 
00187       Matrix A(2,3);
00188       A << 3 << 5 << 2
00189         << 4 << 1 << 6;
00190 
00191       Matrix B(3,4);
00192       B <<  7 <<  2 <<  9 << 11
00193         <<  1 <<  3 <<  6 <<  8
00194         <<  4 << 10 <<  5 << 12;
00195 
00196       RowVector C(2); C << 3 << 7;
00197       ColumnVector D(4); D << 0 << 5 << 13 << 11;
00198 
00199       Matrix M = KP(C * A, B * D) - KP(C, B) * KP(A, D); Print(M);
00200    }
00201 
00202    {
00203       Tracer et1("Stage 6");
00204 
00205       RowVector A(3), B(5), C(15);
00206       A << 5 << 2 << 4;
00207       B << 3 << 2 << 0 << 1 << 6;
00208       C << 15 << 10 << 0 << 5 << 30
00209         <<  6 <<  4 << 0 << 2 << 12
00210         << 12 <<  8 << 0 << 4 << 24;
00211       Matrix N = KP(A, B) - C;    Print(N);
00212       N = KP(A.t(), B.t()) - C.t();    Print(N);
00213       N = KP(A.AsDiagonal(), B.AsDiagonal()) - C.AsDiagonal();    Print(N);
00214    }
00215 
00216 }
00217 
00218 
00219 
00220 
00221 
00222 


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