00001
00002
00003 #include "include.h"
00004 #include "newmatap.h"
00005
00006 #include "tmt.h"
00007
00008 #ifdef use_namespace
00009 using namespace NEWMAT;
00010 #endif
00011
00012
00013
00014
00015
00016 void trymat9()
00017 {
00018 Tracer et("Ninth test of Matrix package");
00019 Tracer::PrintTrace();
00020
00021
00022 int i; int j;
00023 Matrix A(7,7); Matrix X(7,3);
00024 for (i=1;i<=7;i++) for (j=1;j<=7;j++) A(i,j)=i*i+j+((i==j) ? 1 : 0);
00025 for (i=1;i<=7;i++) for (j=1;j<=3;j++) X(i,j)=i-j;
00026 Matrix B = A.i(); DiagonalMatrix D(7); D=1.0;
00027 {
00028 Tracer et1("Stage 1");
00029 Matrix Q = B*A-D; Clean(Q, 0.000000001); Print(Q);
00030 Q=A; Q = Q.i() * X; Q = A*Q - X; Clean(Q, 0.000000001); Print(Q);
00031 Q=X; Q = A.i() * Q; Q = A*Q - X; Clean(Q, 0.000000001); Print(Q);
00032 }
00033 for (i=1;i<=7;i++) D(i,i)=i*i+1;
00034 DiagonalMatrix E(3); for (i=1;i<=3;i++) E(i,i)=i+23;
00035 {
00036 Tracer et1("Stage 2");
00037 Matrix DXE = D.i() * X * E;
00038 DXE = E.i() * DXE.t() * D - X.t(); Clean(DXE, 0.00000001); Print(DXE);
00039 E=D; for (i=1;i<=7;i++) E(i,i)=i*3+1;
00040 }
00041 DiagonalMatrix F=D;
00042 {
00043 Tracer et1("Stage 3");
00044 F=E.i()*F; F=F*E-D; Clean(F,0.00000001); Print(F);
00045 F=E.i()*D; F=F*E-D; Clean(F,0.00000001); Print(F);
00046 }
00047 {
00048 Tracer et1("Stage 4");
00049 F=E; F=F.i()*D; F=F*E-D; Clean(F,0.00000001); Print(F);
00050 }
00051 {
00052 Tracer et1("Stage 5");
00053
00054 ColumnVector A(18), B(18);
00055 Matrix X(3,3);
00056 X << 3 << 5 << 7 << 5 << 8 << 2 << 7 << 2 << 9;
00057 SymmetricMatrix S; S << X;
00058 B(1) = S == X; A(1) = true;
00059 B(2) = S == (X+1); A(2) = false;
00060 B(3) = (S+2) == (X+2); A(3) = true;
00061 Matrix Y = X;
00062 B(4) = X == Y; A(4) = true;
00063 B(5) = (X*2) == (Y*2); A(5) = true;
00064 Y(3,3) = 10;
00065 B(6) = X == Y; A(6) = false;
00066 B(7) = (X*2) == (Y*2); A(7) = false;
00067 B(8) = S == Y; A(8) = false;
00068 B(9) = S == S; A(9) = true;
00069 Matrix Z = X.SubMatrix(1,2,2,3);
00070 B(10) = X == Z; A(10) = false;
00071 GenericMatrix GS = S;
00072 GenericMatrix GX = X;
00073 GenericMatrix GY = Y;
00074 B(11) = GS == GX; A(11) = true;
00075 B(12) = GS == GY; A(12) = false;
00076 CroutMatrix CS = S;
00077 CroutMatrix CX = X;
00078 CroutMatrix CY = Y;
00079 B(13) = CS == CX; A(13) = true;
00080 B(14) = CS == CY; A(14) = false;
00081 B(15) = X == CX; A(15) = false;
00082 B(16) = X == A; A(16) = false;
00083 B(17) = X == (X | X); A(17) = false;
00084 B(18) = CX == X; A(18) = false;
00085 A = A - B; Print(A);
00086 }
00087 {
00088 Tracer et1("Stage 6");
00089
00090 ColumnVector A(22), B(22);
00091 BandMatrix X(6,2,1);
00092 X(1,1)=23; X(1,2)=21;
00093 X(2,1)=12; X(2,2)=17; X(2,3)=45;
00094 X(3,1)=35; X(3,2)=19; X(3,3)=24; X(3,4)=29;
00095 X(4,2)=17; X(4,3)=11; X(4,4)=19; X(4,5)=35;
00096 X(5,3)=10; X(5,4)=44; X(5,5)=23; X(5,6)=31;
00097 X(6,4)=49; X(6,5)=41; X(6,6)=17;
00098 SymmetricBandMatrix S1(6,2); S1.Inject(X);
00099 BandMatrix U(6,2,3); U = 0.0; U.Inject(X);
00100 B(1) = U == X; A(1) = true;
00101 B(2) = U == (X*3); A(2) = false;
00102 B(3) = (U*5) == (X*5); A(3) = true;
00103 Matrix Y = X;
00104 B(4) = X == Y; A(4) = true;
00105 B(5) = (X*2) == (Y*2); A(5) = true;
00106 Y(6,6) = 10;
00107 B(6) = X == Y; A(6) = false;
00108 B(7) = (X*2) == (Y*2); A(7) = false;
00109 B(8) = U == Y; A(8) = false;
00110 B(9) = U == U; A(9) = true;
00111 Matrix Z = X.SubMatrix(1,2,2,3);
00112 B(10) = X == Z; A(10) = false;
00113 GenericMatrix GU = U;
00114 GenericMatrix GX = X;
00115 GenericMatrix GY = Y;
00116 B(11) = GU == GX; A(11) = true;
00117 B(12) = GU == GY; A(12) = false;
00118 X = X + X.t(); U = U + U.t();
00119 SymmetricBandMatrix S(6,2); S.Inject(X);
00120 Matrix D = S-X; Print(D);
00121 BandLUMatrix BS = S;
00122 BandLUMatrix BX = X;
00123 BandLUMatrix BU = U;
00124 CroutMatrix CX = X;
00125 B(13) = BS == BX; A(13) = true;
00126 B(14) = BX == BU; A(14) = false;
00127 B(15) = X == BX; A(15) = false;
00128 B(16) = X != BX; A(16) = true;
00129 B(17) = BX != BS; A(17) = false;
00130 B(18) = (2*X) != (X*2);A(18) = false;
00131 B(19) = (X*2) != (X+2);A(19) = true;
00132 B(20) = BX == CX; A(20) = false;
00133 B(21) = CX == BX; A(21) = false;
00134 B(22) = BX == X; A(22) = false;
00135 A = A - B; Print(A);
00136 DiagonalMatrix I(6); I=1.0;
00137 D = BS.i() * X - I; Clean(D,0.00000001); Print(D);
00138 D = BX.i() * X - I; Clean(D,0.00000001); Print(D);
00139 D = BU.i() * X - I; Clean(D,0.00000001); Print(D);
00140
00141
00142 SymmetricBandMatrix X1(6,2);
00143 X1.Row(1) << 23;
00144 X1.Row(2) << 12 << 17;
00145 X1.Row(3) << 35 << 19 << 24;
00146 X1.Row(4) << 17 << 11 << 19;
00147 X1.Row(5) << 10 << 44 << 23;
00148 X1.Row(6) << 49 << 41 << 17;
00149 Matrix M = X1 - S1; Print(M);
00150
00151
00152 SymmetricBandMatrix X2(20,3); X2 = 0.0;
00153 X2.SubMatrix(2,7,2,7) = X1; X2.SymSubMatrix(11,16) = 2 * X1;
00154 Matrix MX1 = X1;
00155 Matrix MX2(20,20); MX2 = 0;
00156 MX2.SymSubMatrix(2,7) = MX1; MX2.SubMatrix(11,16,11,16) = MX1 * 2;
00157 MX2 -= X2; Print(MX2);
00158
00159 BandMatrix X4(20,3,3); X4 = 0.0;
00160 X4.SubMatrix(2,7,3,8) = X1; X4.SubMatrix(11,16,10,15) = 2 * X1;
00161 MX1 = X1;
00162 Matrix MX4(20,20); MX4 = 0;
00163 MX4.SubMatrix(2,7,3,8) = MX1; MX4.SubMatrix(11,16,10,15) = MX1 * 2;
00164 MX4 -= X4; Print(MX4);
00165
00166 MX1 = X1.i() * X1 - IdentityMatrix(6);
00167 Clean(MX1,0.00000001); Print(MX1);
00168
00169 }
00170
00171 {
00172 Tracer et1("Stage 7");
00173
00174 ColumnVector A(12), B(12);
00175 BandMatrix X(6,2,1);
00176 X(1,1)=23; X(1,2)=21;
00177 X(2,1)=12; X(2,2)=17; X(2,3)=45;
00178 X(3,1)=35; X(3,2)=19; X(3,3)=24; X(3,4)=29;
00179 X(4,2)=17; X(4,3)=11; X(4,4)=19; X(4,5)=35;
00180 X(5,3)=10; X(5,4)=44; X(5,5)=23; X(5,6)=31;
00181 X(6,4)=49; X(6,5)=41; X(6,6)=17;
00182 Matrix Y = X;
00183 LinearEquationSolver LX = X;
00184 LinearEquationSolver LY = Y;
00185 CroutMatrix CX = X;
00186 CroutMatrix CY = Y;
00187 BandLUMatrix BX = X;
00188 B(1) = LX == CX; A(1) = false;
00189 B(2) = LY == CY; A(2) = true;
00190 B(3) = X == Y; A(3) = true;
00191 B(4) = BX == LX; A(4) = true;
00192 B(5) = CX == CY; A(5) = true;
00193 B(6) = LX == LY; A(6) = false;
00194 B(7) = BX == BX; A(7) = true;
00195 B(8) = CX == CX; A(8) = true;
00196 B(9) = LX == LX; A(9) = true;
00197 B(10) = LY == LY; A(10) = true;
00198 CroutMatrix CX1 = X.SubMatrix(1,4,1,4);
00199 B(11) = CX == CX1; A(11) = false;
00200 BandLUMatrix BX1 = X.SymSubMatrix(1,4);
00201 B(12) = BX == BX1; A(12) = false;
00202 A = A - B; Print(A);
00203 DiagonalMatrix I(6); I=1.0; Matrix D;
00204 D = LX.i() * X - I; Clean(D,0.00000001); Print(D);
00205 D = LY.i() * X - I; Clean(D,0.00000001); Print(D);
00206 I.ReSize(4); I = 1;
00207 D = CX1.i() * X.SymSubMatrix(1,4) - I; Clean(D,0.00000001); Print(D);
00208 D = BX1.i() * X.SubMatrix(1,4,1,4) - I; Clean(D,0.00000001); Print(D);
00209 }
00210
00211
00212 }
00213