1 | |
---|
2 | //#define WANT_STREAM |
---|
3 | |
---|
4 | #include "include.h" |
---|
5 | |
---|
6 | #include "newmatap.h" |
---|
7 | //#include "newmatio.h" |
---|
8 | |
---|
9 | #include "tmt.h" |
---|
10 | |
---|
11 | #ifdef use_namespace |
---|
12 | using namespace NEWMAT; |
---|
13 | #endif |
---|
14 | |
---|
15 | |
---|
16 | void trymatj() |
---|
17 | { |
---|
18 | Tracer et("Nineteenth test of Matrix package"); |
---|
19 | Tracer::PrintTrace(); |
---|
20 | // testing elementwise (SP) products |
---|
21 | |
---|
22 | { |
---|
23 | Tracer et1("Stage 1"); |
---|
24 | Matrix A(13,7), B(13,7), C(13,7); |
---|
25 | int i,j; |
---|
26 | for (i=1;i<=13;i++) for (j=1; j<=7; j++) |
---|
27 | { |
---|
28 | Real a = (i+j*j)/2, b = (i*j-i/4); |
---|
29 | A(i,j)=a; B(i,j)=b; C(i,j)=a*b; |
---|
30 | } |
---|
31 | // Where complete matrix routine can be used |
---|
32 | Matrix X = SP(A,B)-C; Print(X); |
---|
33 | X = SP(A,B+1.0)-A-C; Print(X); |
---|
34 | X = SP(A-1,B)+B-C; Print(X); |
---|
35 | X = SP(A-1,B+1)+B-A-C+1; Print(X); |
---|
36 | // Where row-wise routine will be used |
---|
37 | A = A.Rows(7,13); B = B.Rows(7,13); C = C.Rows(7,13); |
---|
38 | LowerTriangularMatrix LTA; LTA << A; |
---|
39 | UpperTriangularMatrix UTB; UTB << B; |
---|
40 | DiagonalMatrix DC; DC << C; |
---|
41 | X = SP(LTA,UTB) - DC; Print(X); |
---|
42 | X = SP(LTA*2,UTB) - DC*2; Print(X); |
---|
43 | X = SP(LTA, UTB /2) - DC/2; Print(X); |
---|
44 | X = SP(LTA/2, UTB*2) - DC; Print(X); |
---|
45 | DiagonalMatrix DX; |
---|
46 | DX << SP(A,B); DX << (DX-C); Print(DX); |
---|
47 | DX << SP(A*4,B); DX << (DX-C*4); Print(DX); |
---|
48 | DX << SP(A,B*2); DX << (DX-C*2); Print(DX); |
---|
49 | DX << SP(A/4,B/4); DX << (DX-C/16); Print(DX); |
---|
50 | LowerTriangularMatrix LX; |
---|
51 | LX = SP(LTA,B); LX << (LX-C); Print(LX); |
---|
52 | LX = SP(LTA*3,B); LX << (LX-C*3); Print(LX); |
---|
53 | LX = SP(LTA,B*5); LX << (LX-C*5); Print(LX); |
---|
54 | LX = SP(-LTA,-B); LX << (LX-C); Print(LX); |
---|
55 | } |
---|
56 | { |
---|
57 | // Symmetric Matrices |
---|
58 | Tracer et1("Stage 2"); |
---|
59 | SymmetricMatrix A(25), B(25), C(25); |
---|
60 | int i,j; |
---|
61 | for (i=1;i<=25;i++) for (j=i;j<=25;j++) |
---|
62 | { |
---|
63 | Real a = i*j +i - j + 3; |
---|
64 | Real b = i * i + j; |
---|
65 | A(i,j)=a; B(i,j)=b; C(i,j)=a*b; |
---|
66 | } |
---|
67 | UpperTriangularMatrix UT; |
---|
68 | UT << SP(A,B); UT << (UT - C); Print(UT); |
---|
69 | Matrix MA = A, X; |
---|
70 | X = SP(MA,B)-C; Print(X); |
---|
71 | X = SP(A,B)-C; Print(X); |
---|
72 | SymmetricBandMatrix BA(25,5), BB(25,5), BC(25,5); |
---|
73 | BA.Inject(A); BB.Inject(B); BC.Inject(C); |
---|
74 | X = SP(BA,BB)-BC; Print(X); |
---|
75 | X = SP(BA*7,BB)-BC*7; Print(X); |
---|
76 | X = SP(BA,BB/8)-BC/8; Print(X); |
---|
77 | X = SP(BA*16,BB/16)-BC; Print(X); |
---|
78 | X = SP(BA,BB); X=X-BC; Print(X); |
---|
79 | X = SP(BA*2, BB/2)-BC; Print(X); |
---|
80 | X = SP(BA, BB/2)-BC/2; Print(X); |
---|
81 | X = SP(BA*2, BB)-BC*2; Print(X); |
---|
82 | } |
---|
83 | { |
---|
84 | // Band matrices |
---|
85 | Tracer et1("Stage 3"); |
---|
86 | Matrix A(19,19), B(19,19), C(19,19); |
---|
87 | int i,j; |
---|
88 | for (i=1;i<=19;i++) for (j=1;j<=19;j++) |
---|
89 | { |
---|
90 | Real a = i*j +i - 1.5*j + 3; |
---|
91 | Real b = i * i + j; |
---|
92 | A(i,j)=a; B(i,j)=b; C(i,j)=a*b; |
---|
93 | } |
---|
94 | BandMatrix BA(19,10,7), BB(19,8,15), BC(19,8,7); |
---|
95 | BA.Inject(A); BB.Inject(B); BC.Inject(C); |
---|
96 | Matrix X; BandMatrix BX; ColumnVector BW(2); |
---|
97 | X = SP(BA,BB); X=X-BC; Print(X); |
---|
98 | X = SP(BA/8,BB); X=X-BC/8; Print(X); |
---|
99 | X = SP(BA,BB*17); X=X-BC*17; Print(X); |
---|
100 | X = SP(BA/4,BB*7); X=X-BC*7/4; Print(X); |
---|
101 | X = SP(BA,BB)-BC; Print(X); |
---|
102 | X = SP(BA/8,BB)-BC/8; Print(X); |
---|
103 | X = SP(BA,BB*17)-BC*17; Print(X); |
---|
104 | X = SP(BA/4,BB*7)-BC*7/4; Print(X); |
---|
105 | BX = SP(BA,BB); |
---|
106 | BW(1)=BX.upper-7; BW(2)=BX.lower-8; Print(BW); |
---|
107 | |
---|
108 | BA.ReSize(19,7,10); BB.ReSize(19,15,8); |
---|
109 | BC.ReSize(19,7,8); |
---|
110 | BA.Inject(A); BB.Inject(B); BC.Inject(C); |
---|
111 | |
---|
112 | X = SP(BA,BB); X=X-BC; Print(X); |
---|
113 | X = SP(BA/8,BB); X=X-BC/8; Print(X); |
---|
114 | X = SP(BA,BB*17); X=X-BC*17; Print(X); |
---|
115 | X = SP(BA/4,BB*7); X=X-BC*7/4; Print(X); |
---|
116 | X = SP(BA,BB)-BC; Print(X); |
---|
117 | X = SP(BA/8,BB)-BC/8; Print(X); |
---|
118 | X = SP(BA,BB*17)-BC*17; Print(X); |
---|
119 | X = SP(BA/4,BB*7)-BC*7/4; Print(X); |
---|
120 | BX = SP(BA,BB); |
---|
121 | BW(1)=BX.upper-8; BW(2)=BX.lower-7; Print(BW); |
---|
122 | } |
---|
123 | { |
---|
124 | // SymmetricBandMatrices |
---|
125 | Tracer et1("Stage 4"); |
---|
126 | Matrix A(7,7), B(7,7); |
---|
127 | int i,j; |
---|
128 | for (i=1;i<=7;i++) for (j=1;j<=7;j++) |
---|
129 | { |
---|
130 | Real a = i*j +i - 1.5*j + 3; |
---|
131 | Real b = i * i + j; |
---|
132 | A(i,j)=a; B(i,j)=b; |
---|
133 | } |
---|
134 | BandMatrix BA(7,2,4), BB(7,3,1), BC(7,2,1); |
---|
135 | BA.Inject(A); |
---|
136 | SymmetricBandMatrix SB(7,3); |
---|
137 | SymmetricMatrix S; S << (B+B.t()); |
---|
138 | SB.Inject(S); A = BA; S = SB; |
---|
139 | Matrix X; |
---|
140 | X = SP(BA,SB); X=X-SP(A,S); Print(X); |
---|
141 | X = SP(BA*2,SB); X=X-SP(A,S*2); Print(X); |
---|
142 | X = SP(BA,SB/4); X=X-SP(A/4,S); Print(X); |
---|
143 | X = SP(BA*4,SB/4); X=X-SP(A,S); Print(X); |
---|
144 | X = SP(BA,SB)-SP(A,S); Print(X); |
---|
145 | X = SP(BA*2,SB)-SP(A,S*2); Print(X); |
---|
146 | X = SP(BA,SB/4)-SP(A/4,S); Print(X); |
---|
147 | X = SP(BA*4,SB/4)-SP(A,S); Print(X); |
---|
148 | } |
---|
149 | |
---|
150 | } |
---|
151 | |
---|
152 | |
---|