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


kni
Author(s): Martin Günther
autogenerated on Fri Jan 3 2020 04:01:17