Go to the documentation of this file.00001
00002
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
00016
00017
00018
00019 ReturnMatrix Returner0(const GenericMatrix& GM)
00020 { Matrix M = GM; M.Release(); return M; }
00021
00022 ReturnMatrix Returner1(const GenericMatrix& GM)
00023 { Matrix M = GM+1; M.Release(); return M; }
00024
00025 ReturnMatrix Returner2(const GenericMatrix& GM)
00026 { UpperBandMatrix M = GM*2; M.Release(); return M; }
00027
00028 ReturnMatrix Returner3(const GenericMatrix& GM)
00029 { LowerBandMatrix M = GM*3; M.Release(); return M; }
00030
00031 ReturnMatrix Returner4(const GenericMatrix& GM)
00032 { SymmetricMatrix M = GM+4; M.Release(); return M; }
00033
00034 ReturnMatrix Returner5(const GenericMatrix& GM)
00035 { SymmetricBandMatrix M = GM*5; M.Release(); return M; }
00036
00037 ReturnMatrix Returner6(const GenericMatrix& GM)
00038 { BandMatrix M = GM*6; M.Release(); return M; }
00039
00040 ReturnMatrix Returner7(const GenericMatrix& GM)
00041 { DiagonalMatrix M = GM*7; M.Release(); return M; }
00042
00043 void trymat5()
00044 {
00045
00046 Tracer et("Fifth test of Matrix package");
00047 Tracer::PrintTrace();
00048
00049 int i,j;
00050
00051 Matrix A(5,6);
00052 for (i=1;i<=5;i++) for (j=1;j<=6;j++) A(i,j)=1+i*j+i*i+j*j;
00053 ColumnVector CV(6);
00054 for (i=1;i<=6;i++) CV(i)=i*i+3;
00055 ColumnVector CV2(5); for (i=1;i<=5;i++) CV2(i)=1.0;
00056 ColumnVector CV1=CV;
00057
00058 {
00059 CV=A*CV;
00060 RowVector RV=CV.t();
00061 RV=RV-1.0;
00062 CV=(RV*A).t()+A.t()*CV2; CV1=(A.t()*A)*CV1 - CV;
00063 Print(CV1);
00064 }
00065
00066 CV1.ReSize(6);
00067 CV2.ReSize(6);
00068 CV.ReSize(6);
00069 for (i=1;i<=6;i++) { CV1(i)=i*3+1; CV2(i)=10-i; CV(i)=11+i*2; }
00070 ColumnVector CX=CV2-CV; { CX=CX+CV1; Print(CX); }
00071 Print(ColumnVector(CV1+CV2-CV));
00072 RowVector RV=CV.t(); RowVector RV1=CV1.t();
00073 RowVector R=RV-RV1; Print(RowVector(R-CV2.t()));
00074
00075
00076
00077 RV.ReSize(10);
00078 for (i=1;i<=10;i++) RV(i) = i*i;
00079 RV1.ReSize(10);
00080 RV1 << 1 << 4 << 9 << 16 << 25 << 36 << 49 << 64 << 81 << 100;
00081 Print(RowVector(RV-RV1));
00082
00083 et.ReName("Fifth test of Matrix package - almost at end");
00084
00085 Matrix X(2,3);
00086 X << 11 << 12 << 13
00087 << 21 << 22 << 23;
00088
00089 Matrix Y = X.t();
00090
00091 X(1,1) -= 11; X(1,2) -= 12; X(1,3) -= 13;
00092 X(2,1) -= 21; X(2,2) -= 22; X(2,3) -= 23;
00093 Print(X);
00094
00095 Y(1,1) -= 11; Y(2,1) -= 12; Y(3,1) -= 13;
00096 Y(1,2) -= 21; Y(2,2) -= 22; Y(3,2) -= 23;
00097 Print(Y);
00098
00099 et.ReName("Fifth test of Matrix package - at end");
00100
00101 RV = Returner1(RV)-1; Print(RowVector(RV-RV1));
00102 CV1 = Returner1(RV.t())-1; Print(ColumnVector(RV.t()-CV1));
00103 #ifndef DONT_DO_NRIC
00104 nricMatrix AA = A;
00105 X = Returner1(AA)-A-1; Print(X);
00106 #endif
00107 UpperTriangularMatrix UT(31);
00108 for (i=1; i<=31; i++) for (j=i; j<=31; j++) UT(i,j) = i+j+(i-j)*(i-2*j);
00109 UpperBandMatrix UB(31,5); UB.Inject(UT);
00110 LowerTriangularMatrix LT = UT.t();
00111 LowerBandMatrix LB(31,5); LB.Inject(LT);
00112 A = Returner0(UB)-LB.t(); Print(A);
00113 A = Returner2(UB).t()-LB*2; Print(A);
00114 A = Returner3(LB).t()-UB*3; Print(A);
00115 SymmetricMatrix SM; SM << (UT+LT);
00116 A = Returner4(SM)-UT-LT-4; Print(A);
00117 SymmetricBandMatrix SB(31,5); SB.Inject(SM);
00118 A = Returner5(SB)/5-UB-LB; Print(A);
00119 BandMatrix B = UB+LB*LB; A = LB;
00120 A = Returner6(B)/6 - UB - A*A; Print(A);
00121 DiagonalMatrix D; D << UT;
00122 D << (Returner7(D)/7 - UT); Print(D);
00123
00124
00125 }