tmt7.cc
Go to the documentation of this file.
00001 
00002 //#define WANT_STREAM
00003 
00004 #include "include.h"
00005 
00006 #include "newmat.h"
00007 
00008 #include "tmt.h"
00009 
00010 #ifdef use_namespace
00011 using namespace NEWMAT;
00012 #endif
00013 
00014 
00015 /**************************** test program ******************************/
00016 
00017 
00018 void trymat7()
00019 {
00020 //   cout << "\nSeventh test of Matrix package\n";
00021    Tracer et("Seventh test of Matrix package");
00022    Tracer::PrintTrace();
00023 
00024    int i,j;
00025 
00026 
00027    DiagonalMatrix D(6);
00028    UpperTriangularMatrix U(6);
00029    for (i=1;i<=6;i++) { for (j=i;j<=6;j++) U(i,j)=i*i*j-50; D(i,i)=i*i+i-10; }
00030    LowerTriangularMatrix L=(U*3.0).t();
00031    SymmetricMatrix S(6);
00032    for (i=1;i<=6;i++) for (j=i;j<=6;j++) S(i,j)=i*i+2.0+j;
00033    Matrix MD=D; Matrix ML=L; Matrix MU=U;
00034    Matrix MS=S;
00035    Matrix M(6,6);
00036    for (i=1;i<=6;i++) for (j=1;j<=6;j++) M(i,j)=i*j+i*i-10.0;  
00037    {
00038       Tracer et1("Stage 1");
00039       Print(Matrix((S-M)-(MS-M)));
00040       Print(Matrix((-M-S)+(MS+M)));
00041       Print(Matrix((U-M)-(MU-M)));
00042    }
00043    {
00044       Tracer et1("Stage 2");
00045       Print(Matrix((L-M)+(M-ML)));
00046       Print(Matrix((D-M)+(M-MD)));
00047       Print(Matrix((D-S)+(MS-MD)));
00048       Print(Matrix((D-L)+(ML-MD)));
00049    }
00050 
00051    { M=MU.t(); }
00052    LowerTriangularMatrix LY=D.i()*U.t();
00053    {
00054       Tracer et1("Stage 3");
00055       MS=D*LY-M; Clean(MS,0.00000001); Print(MS);
00056       L=U.t();
00057       LY=D.i()*L; MS=D*LY-M; Clean(MS,0.00000001); Print(MS);
00058    }
00059    {
00060       Tracer et1("Stage 4");
00061       UpperTriangularMatrix UT(11);
00062       int i, j;
00063       for (i=1;i<=11;i++) for (j=i;j<=11;j++) UT(i,j)=i*i+j*3;
00064       GenericMatrix GM; Matrix X;
00065       UpperBandMatrix UB(11,3); UB.Inject(UT); UT = UB;
00066       UpperBandMatrix UB2 = UB / 8;
00067       GM = UB2-UT/8; X = GM; Print(X);
00068       SymmetricBandMatrix SB(11,4); SB << (UB + UB.t());
00069       X = SB - UT - UT.t(); Print(X);
00070       BandMatrix B = UB + UB.t()*2;
00071       DiagonalMatrix D; D << B;
00072       X.ReSize(1,1); X(1,1) = Trace(B)-Sum(D); Print(X);
00073       X = SB + 5; Matrix X1=X; X = SP(UB,X); Matrix X2 =UB;
00074       X1 = (X1.AsDiagonal() * X2.AsDiagonal()).AsRow()-X.AsColumn().t();
00075       Print(X1);
00076       X1=SB.t(); X2 = B.t(); X = SB.i() * B - X1.i() * X2.t();
00077       Clean(X,0.00000001); Print(X);
00078       X = SB.i(); X = X * B - X1.i() * X2.t();
00079       Clean(X,0.00000001); Print(X);
00080       D = 1; X = SB.i() * SB - D; Clean(X,0.00000001); Print(X);
00081       ColumnVector CV(11);
00082       CV << 2 << 6 <<3 << 8 << -4 << 17.5 << 2 << 1 << -2 << 5 << 3.75;
00083       D << 2 << 6 <<3 << 8 << -4 << 17.5 << 2 << 1 << -2 << 5 << 3.75;
00084       X = CV.AsDiagonal(); X = X-D; Print(X);
00085       SymmetricBandMatrix SB1(11,7); SB1 = 5; 
00086       SymmetricBandMatrix SB2 = SB1 + D;
00087       X.ReSize(11,11); X=0;
00088       for (i=1;i<=11;i++) for (j=1;j<=11;j++)
00089       {
00090          if (abs(i-j)<=7) X(i,j)=5;
00091          if (i==j) X(i,j)+=CV(i);
00092       }
00093       SymmetricMatrix SM; SM.ReSize(11);
00094       SM=SB; SB = SB+SB2; X1 = SM+X-SB; Print(X1);
00095       SB2=0; X2=SB2; X1=SB; Print(X2);
00096       for (i=1;i<=11;i++) SB2.Column(i)<<SB.Column(i);
00097       X1=X1-SB2; Print(X1);
00098       X = SB; SB2.ReSize(11,4); SB2 = SB*5; SB2 = SB + SB2;
00099       X1 = X*6 - SB2; Print(X1);
00100       X1 = SP(SB,SB2/3); X1=X1-SP(X,X*2); Print(X1);
00101       X1 = SP(SB2/6,X*2); X1=X1-SP(X*2,X); Print(X1);
00102    }
00103 
00104    {
00105       // test the simple integer array class
00106       Tracer et("Stage 5");
00107       ColumnVector Test(10); Test = 0.0;
00108       int i;
00109       SimpleIntArray A(100);
00110       for (i = 0; i < 100; i++) A[i] = i*i+1;
00111       SimpleIntArray B(100), C(50), D(0);
00112       D.ReSize(150);
00113       B = A; A.ReSize(50, true); C = A; A.ReSize(150, true); D = A;
00114       for (i = 0; i < 100; i++) if (B[i] != i*i+1) Test(1)=1;
00115       for (i = 0; i < 50; i++) if (C[i] != i*i+1) Test(2)=1;
00116       for (i = 0; i < 50; i++) if (D[i] != i*i+1) Test(3)=1;
00117       A.ReSize(75); A = A.Size();
00118       for (i = 0; i < 75; i++) if (A[i] != 75) Test(4)=1;
00119       A.ReSize(25); A = A.Size();
00120       for (i = 0; i < 25; i++) if (A[i] != 25) Test(5)=1;
00121       A.ReSize(25); A = 23;
00122       for (i = 0; i < 25; i++) if (A[i] != 23) Test(6)=1;
00123       A.ReSize(0); A.ReSize(15); A = A.Size();
00124       for (i = 0; i < 15; i++) if (A[i] != 15) Test(7)=1;
00125       const SimpleIntArray E = B;
00126       for (i = 0; i < 100; i++) if (E[i] != i*i+1) Test(8)=1;
00127       Print(Test);
00128    }
00129 
00130 
00131 //   cout << "\nEnd of seventh test\n";
00132 }


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