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 class TestClass
00020 {
00021 Matrix A;
00022 Matrix B;
00023 public:
00024 TestClass();
00025 ReturnMatrix Sum();
00026 };
00027
00028 TestClass::TestClass() : A(2,3)
00029 {
00030 B.ReSize(2,3);
00031 A << 1 << 4
00032 << 4 << 1
00033 << 2 << 9;
00034 B << 8 << 5
00035 << 5 << 8
00036 << 7 << 0;
00037 }
00038
00039 ReturnMatrix TestClass::Sum() { return Matrix(A + B).ForReturn(); }
00040
00041
00042
00043 void trymatb()
00044 {
00045
00046 Tracer et("Eleventh test of Matrix package");
00047 Tracer::PrintTrace();
00048 int i; int j;
00049 RowVector RV; RV.ReSize(10);
00050 {
00051 Tracer et1("Stage 1");
00052 for (i=1;i<=10;i++) RV(i)=i*i-3;
00053 Matrix X(1,1); X(1,1) = .25;
00054 Print(RowVector(X.i() * RV - RV / .25));
00055
00056 Print(RowVector(X.i() * RV - RV / .25));
00057 }
00058 LowerTriangularMatrix L(5); UpperTriangularMatrix U(5);
00059 for (i=1; i<=5; i++) for (j=1; j<=i; j++)
00060 { L(i,j) = i*i + j -2.0; U(j,i) = i*i*j+3; }
00061 DiagonalMatrix D(5);
00062 for (i=1; i<=5; i++) D(i,i) = i*i + i + 2;
00063 Matrix M1 = -L; Matrix M2 = L-U; Matrix M3 = U*3; Matrix M4 = U-L;
00064 Matrix M5 = M1 - D; M1 = D * (-3) - M3;
00065 {
00066 Tracer et1("Stage 2");
00067 Print(Matrix((M2-M4*2)+M5*3-M1));
00068 M1 = L.t(); Print(Matrix(M1.t()-L));
00069 M1 = U.t(); Print(Matrix(M1.t()-U));
00070 }
00071 {
00072 Tracer et1("Stage 3");
00073 SymmetricMatrix S(5);
00074 for (i=1; i<=5; i++) for (j=1; j<=i; j++) S(i,j) = i*j+i-j+5;
00075 M2 = S.i() * M4; M1 = S; M3=M1*M2-M4; Clean(M3,0.00000001); Print(M3);
00076 SymmetricMatrix T(5);
00077 for (i=1; i<=5; i++) for (j=1; j<=i; j++) T(i,j) = i*i*j*j+i-j+5-i*j;
00078 M1 = S.i() * T; M1 = S * M1; M1 = M1-T; Clean(M1,0.00000001); Print(M1);
00079 ColumnVector CV(5); for (i=1; i<=5; i++) CV(i) = i*i*i+10;
00080 M1 = CV * RV;
00081 }
00082 {
00083 Tracer et1("Stage 4");
00084 M4.ReSize(5,10);
00085 for (i=1; i<=5; i++) for (j=1; j<=10; j++) M4(i,j) = (i*i*i+10)*(j*j-3);
00086 Print(Matrix(M1-M4));
00087 M1 = L.t(); M2 = U.t(); M3 = L+U; Print(Matrix(M1-M3.t()+M2));
00088 }
00089
00090 UpperTriangularMatrix U2((UpperTriangularMatrix&)U);
00091 {
00092 Tracer et1("Stage 5");
00093 Print(Matrix(U2-U));
00094 M2.ReSize(10,10);
00095 for (i=1; i<=10; i++) for (j=1; j<=10; j++) M2(i,j) = (i*i*i+10)*(j*j-3);
00096 D << M2; L << M2; U << M2;
00097 Print( Matrix( (D+M2)-(L+U) ) );
00098 }
00099 {
00100 Tracer et1("Stage 6");
00101 M1.ReSize(6,10);
00102 for (i=1; i<=6; i++) for (j=1; j<=10; j++) M1(i,j) = 100*i + j;
00103 M2 = M1.SubMatrix(3,5,4,7); M3.ReSize(3,4);
00104 for (i=3; i<=5; i++) for (j=4; j<=7; j++) M3(i-2,j-3) = 100*i + j;
00105 Print(Matrix(M2-M3));
00106 }
00107 int a1,a2,a3,a4;
00108 {
00109 Tracer et1("Stage 7");
00110 int a1,a2,a3,a4;
00111 a1=4; a2=9; a3=4; a4=7;
00112 U.ReSize(10);
00113 for (i=1; i<=10; i++) for (j=i; j<=10; j++) U(i,j) = 100*i + j;
00114 M2 = U.SubMatrix(a1,a2,a3,a4);
00115 M3.ReSize(a2-a1+1,a4-a3+1); M3=0.0;
00116 for (i=a1; i<=a2; i++) for (j=(i>a3) ? i : a3; j<=a4; j++)
00117 M3(i-a1+1,j-a3+1) = 100*i + j;
00118 Print(Matrix(M2-M3));
00119 }
00120 {
00121 Tracer et1("Stage 8");
00122 a1=3; a2=9; a3=2; a4=7;
00123 U.ReSize(10);
00124 for (i=1; i<=10; i++) for (j=i; j<=10; j++) U(i,j) = 100*i + j;
00125 M2 = U.SubMatrix(a1,a2,a3,a4);
00126 M3.ReSize(a2-a1+1,a4-a3+1); M3=0.0;
00127 for (i=a1; i<=a2; i++) for (j=(i>a3) ? i : a3; j<=a4; j++)
00128 M3(i-a1+1,j-a3+1) = 100*i + j;
00129 Print(Matrix(M2-M3));
00130 }
00131 {
00132 Tracer et1("Stage 9");
00133 a1=4; a2=6; a3=2; a4=5;
00134 U.ReSize(10);
00135 for (i=1; i<=10; i++) for (j=i; j<=10; j++) U(i,j) = 100*i + j;
00136 M2 = U.SubMatrix(a1,a2,a3,a4);
00137 M3.ReSize(a2-a1+1,a4-a3+1); M3=0.0;
00138 for (i=a1; i<=a2; i++) for (j=(i>a3) ? i : a3; j<=a4; j++)
00139 M3(i-a1+1,j-a3+1) = 100*i + j;
00140 Print(Matrix(M2-M3));
00141 }
00142
00143 {
00144 Tracer et1("Stage 10");
00145 TestClass TC;
00146 Matrix M = TC.Sum() - 9;
00147 Print(M);
00148 }
00149
00150
00151
00152 }