tmtj.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 "newmatap.h"
00013 //#include "newmatio.h"
00014 
00015 #include "tmt.h"
00016 
00017 #ifdef use_namespace
00018 using namespace NEWMAT;
00019 #endif
00020 
00021 
00022 void trymatj()
00023 {
00024    Tracer et("Nineteenth test of Matrix package");
00025    Tracer::PrintTrace();
00026    // testing elementwise (SP) products
00027 
00028    {
00029       Tracer et1("Stage 1");
00030       Matrix A(13,7), B(13,7), C(13,7);
00031       int i,j;
00032       for (i=1;i<=13;i++) for (j=1; j<=7; j++)
00033       {
00034           Real a = (i+j*j)/2, b = (i*j-i/4);
00035           A(i,j)=a; B(i,j)=b; C(i,j)=a*b;
00036       }
00037       // Where complete matrix routine can be used
00038       Matrix X = SP(A,B)-C; Print(X);
00039       X = SP(A,B+1.0)-A-C; Print(X);
00040       X = SP(A-1,B)+B-C; Print(X);
00041       X = SP(A-1,B+1)+B-A-C+1; Print(X);
00042       // Where row-wise routine will be used
00043       A = A.Rows(7,13); B = B.Rows(7,13); C = C.Rows(7,13);
00044       LowerTriangularMatrix LTA; LTA << A;
00045       UpperTriangularMatrix UTB; UTB << B;
00046       DiagonalMatrix DC; DC << C;
00047       X = SP(LTA,UTB) - DC; Print(X);
00048       X = SP(LTA*2,UTB) - DC*2; Print(X);
00049       X = SP(LTA, UTB /2) - DC/2; Print(X);
00050       X = SP(LTA/2, UTB*2) - DC; Print(X);
00051       DiagonalMatrix DX;
00052       DX << SP(A,B); DX << (DX-C); Print(DX);
00053       DX << SP(A*4,B); DX << (DX-C*4); Print(DX);
00054       DX << SP(A,B*2); DX << (DX-C*2); Print(DX);
00055       DX << SP(A/4,B/4); DX << (DX-C/16); Print(DX);
00056       LowerTriangularMatrix LX;
00057       LX = SP(LTA,B); LX << (LX-C); Print(LX);
00058       LX = SP(LTA*3,B); LX << (LX-C*3); Print(LX);
00059       LX = SP(LTA,B*5); LX << (LX-C*5); Print(LX);
00060       LX = SP(-LTA,-B); LX << (LX-C); Print(LX);
00061    }
00062    {
00063       // Symmetric Matrices
00064       Tracer et1("Stage 2");
00065       SymmetricMatrix A(25), B(25), C(25);
00066       int i,j;
00067       for (i=1;i<=25;i++) for (j=i;j<=25;j++)
00068       {
00069          Real a = i*j +i - j + 3;
00070          Real b = i * i + j;
00071          A(i,j)=a; B(i,j)=b; C(i,j)=a*b;
00072       }
00073       UpperTriangularMatrix UT;
00074       UT << SP(A,B); UT << (UT - C); Print(UT);
00075       Matrix MA = A, X;
00076       X = SP(MA,B)-C; Print(X);
00077       X = SP(A,B)-C; Print(X);
00078       SymmetricBandMatrix BA(25,5), BB(25,5), BC(25,5);
00079       BA.Inject(A); BB.Inject(B); BC.Inject(C);
00080       X = SP(BA,BB)-BC; Print(X);
00081       X = SP(BA*7,BB)-BC*7; Print(X);
00082       X = SP(BA,BB/8)-BC/8; Print(X);
00083       X = SP(BA*16,BB/16)-BC; Print(X);
00084       X = SP(BA,BB); X=X-BC; Print(X);
00085       X = SP(BA*2, BB/2)-BC; Print(X);
00086       X = SP(BA, BB/2)-BC/2; Print(X);
00087       X = SP(BA*2, BB)-BC*2; Print(X);
00088    }
00089    {
00090       // Band matrices
00091       Tracer et1("Stage 3");
00092       Matrix A(19,19), B(19,19), C(19,19);
00093       int i,j;
00094       for (i=1;i<=19;i++) for (j=1;j<=19;j++)
00095       {
00096          Real a = i*j +i - 1.5*j + 3;
00097          Real b = i * i + j;
00098          A(i,j)=a; B(i,j)=b; C(i,j)=a*b;
00099       }
00100       BandMatrix BA(19,10,7), BB(19,8,15), BC(19,8,7);
00101       BA.Inject(A); BB.Inject(B); BC.Inject(C);
00102       Matrix X; BandMatrix BX; ColumnVector BW(2);
00103       X = SP(BA,BB); X=X-BC; Print(X);
00104       X = SP(BA/8,BB); X=X-BC/8; Print(X);
00105       X = SP(BA,BB*17); X=X-BC*17; Print(X);
00106       X = SP(BA/4,BB*7); X=X-BC*7/4; Print(X);
00107       X = SP(BA,BB)-BC; Print(X);
00108       X = SP(BA/8,BB)-BC/8; Print(X);
00109       X = SP(BA,BB*17)-BC*17; Print(X);
00110       X = SP(BA/4,BB*7)-BC*7/4; Print(X);
00111       BX = SP(BA,BB);
00112       BW(1)=BX.upper_val-7; BW(2)=BX.lower_val-8; Print(BW);
00113 
00114       BA.ReSize(19,7,10); BB.ReSize(19,15,8);
00115       BC.ReSize(19,7,8);
00116       BA.Inject(A); BB.Inject(B); BC.Inject(C);
00117 
00118       X = SP(BA,BB); X=X-BC; Print(X);
00119       X = SP(BA/8,BB); X=X-BC/8; Print(X);
00120       X = SP(BA,BB*17); X=X-BC*17; Print(X);
00121       X = SP(BA/4,BB*7); X=X-BC*7/4; Print(X);
00122       X = SP(BA,BB)-BC; Print(X);
00123       X = SP(BA/8,BB)-BC/8; Print(X);
00124       X = SP(BA,BB*17)-BC*17; Print(X);
00125       X = SP(BA/4,BB*7)-BC*7/4; Print(X);
00126       BX = SP(BA,BB);
00127       BW(1)=BX.upper_val-8; BW(2)=BX.lower_val-7; Print(BW);
00128    }
00129    {
00130       // SymmetricBandMatrices
00131       Tracer et1("Stage 4");
00132       Matrix A(7,7), B(7,7);
00133       int i,j;
00134       for (i=1;i<=7;i++) for (j=1;j<=7;j++)
00135       {
00136          Real a = i*j +i - 1.5*j + 3;
00137          Real b = i * i + j;
00138          A(i,j)=a; B(i,j)=b;
00139       }
00140       BandMatrix BA(7,2,4), BB(7,3,1), BC(7,2,1);
00141       BA.Inject(A);
00142       SymmetricBandMatrix SB(7,3);
00143       SymmetricMatrix S; S << (B+B.t());
00144       SB.Inject(S); A = BA; S = SB;
00145       Matrix X;  
00146       X = SP(BA,SB); X=X-SP(A,S); Print(X);
00147       X = SP(BA*2,SB); X=X-SP(A,S*2); Print(X);
00148       X = SP(BA,SB/4); X=X-SP(A/4,S); Print(X);
00149       X = SP(BA*4,SB/4); X=X-SP(A,S); Print(X);
00150       X = SP(BA,SB)-SP(A,S); Print(X);
00151       X = SP(BA*2,SB)-SP(A,S*2); Print(X);
00152       X = SP(BA,SB/4)-SP(A/4,S); Print(X);
00153       X = SP(BA*4,SB/4)-SP(A,S); Print(X);
00154    }
00155 
00156 }
00157 
00158 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


kni
Author(s): Neuronics AG (see AUTHORS.txt); ROS wrapper by Martin Günther
autogenerated on Tue May 28 2013 14:52:55