source: Sophya/trunk/SophyaProg/Tests/tsttmat.cc@ 491

Last change on this file since 491 was 491, checked in by ansari, 26 years ago

Ajout programmes test (TMatrix Vector ...) Reza+cmv 21/10/99

File size: 6.5 KB
Line 
1#include "machdefs.h"
2#include <iostream.h>
3#include <stdlib.h>
4#include <stdio.h>
5#include <string.h>
6#include <math.h>
7#include "outilsinit.h"
8#include "pexceptions.h"
9#include "matrix.h"
10#include "tmatrix.h"
11#include "nbrandom.h"
12
13using namespace PlanckDPC;
14
15////////////////////////////////////////////////////////////////////////////////////////
16int main(int narg,char *arg[])
17{
18PeidaInit();
19r_8 v[3][4] = {{1,2,3,4},{4,5,6,5},{7,8,9,10}};
20
21{
22
23TMatrix<r_8> A(2,3);
24{for(int i=0;i<2;i++) for(int j=0;j<3;j++) A(i,j) = v[i][j];}
25cout<<"A:"<<endl<<A;
26
27{
28cout << " Test ecriture PPersist TMatrix " << endl;
29FIO_TMatrix<r_8> ftm(A);
30ftm.Write("tmtx.ppf");
31}
32{
33cout << " Test lecture PPersist TMatrix " << endl;
34FIO_TMatrix<r_8> ftm("tmtx.ppf");
35cout<<"Alue:"<<(TMatrix<r_8>)ftm<<endl;
36}
37
38cout<<"Matrices B(2,3)"<<endl;
39TMatrix<r_8> B(3,2);
40{for(int i=0;i<3;i++) for(int j=0;j<2;j++) B(i,j) = v[i][j];}
41cout<<"B:"<<endl<<B;
42
43cout<<"Matrices C(3,3)"<<endl;
44TMatrix<r_8> C(3,3);
45{for(int i=0;i<3;i++) for(int j=0;j<3;j++) C(i,j) = v[i][j];}
46cout<<"C:"<<endl<<C;
47
48cout<<"Matrices D(2,2)"<<endl;
49TMatrix<r_8> D(2,2);
50{for(int i=0;i<2;i++) for(int j=0;j<2;j++) D(i,j) = v[i][j];}
51cout<<"D:"<<endl<<D;
52
53cout<<"Matrices E(3,4)"<<endl;
54TMatrix<r_8> E(3,4);
55{for(int i=0;i<3;i++) for(int j=0;j<4;j++) E(i,j) = v[i][j];}
56cout<<"E:"<<endl<<E;
57
58//-----------------------------------------------
59cout<<endl<<"Matrices AA(A)"<<endl;
60TMatrix<r_8> AA(A);
61cout<<"AA:"<<endl<<AA;
62
63//-----------------------------------------------
64cout<<endl<<"Matrices AA2; AA2=A;"<<endl;
65TMatrix<r_8> AA2; AA2=A;
66cout<<"AA2:"<<endl<<AA2;
67
68//-----------------------------------------------
69cout<<endl<<"Matrices AAA.Clone(A)"<<endl;
70TMatrix<r_8> AAA; AAA.Clone(A);
71cout<<"AAA:"<<endl<<AAA;
72cout<<endl<<"Matrices BBB.Clone(B)"<<endl;
73TMatrix<r_8> BBB; BBB.Clone(B);
74cout<<"BBB:"<<endl<<BBB;
75cout<<"Matrices CCC.Clone(C)"<<endl;
76TMatrix<r_8> CCC; CCC.Clone(C);
77cout<<"CCC:"<<endl<<CCC;
78
79//-----------------------------------------------
80cout<<endl<<"Matrices I(5,5)=1.234"<<endl;
81TMatrix<r_8> I(5,5); I = 5;
82cout<<"I:"<<endl<<I;
83
84//-----------------------------------------------
85cout<<endl<<"Matrices AAA+=1"<<endl;
86AAA += 1;
87cout<<"AAA:"<<endl<<AAA;
88cout<<"Matrices AAA-=1"<<endl;
89AAA -= 1;
90cout<<"AAA:"<<endl<<AAA;
91cout<<"Matrices AAA*=10"<<endl;
92AAA *= 10;
93cout<<"AAA:"<<endl<<AAA;
94cout<<"Matrices AAA/=10"<<endl;
95AAA /= 10;
96cout<<"AAA:"<<endl<<AAA;
97
98//-----------------------------------------------
99cout<<endl<<"Matrices AAA+=A"<<endl;
100AAA += A;
101cout<<"AAA:"<<endl<<AAA;
102cout<<"Matrices AAA-=A"<<endl;
103AAA -= A;
104cout<<"AAA:"<<endl<<AAA;
105
106//-----------------------------------------------
107cout<<endl<<"Matrices AAA=A"<<endl;
108AAA = A;
109cout<<"AAA:"<<endl<<AAA;
110cout<<endl<<"Matrices BBB=B"<<endl;
111BBB = B;
112cout<<"BBB:"<<endl<<BBB;
113
114//---------------------------------------------
115TMatrix<r_8> a(A,false);
116cout<<endl<<"Matrices AAA*=C"<<endl;
117{for(int i=0;i<AAA.NRows();i++) for(int j=0;j<C.NCols();j++)
118 {a(i,j) = 0; for(int k=0;k<AAA.NCols();k++) a(i,j) += AAA(i,k)*C(k,j);}}
119AAA *= C;
120cout<<"AAA:"<<endl<<AAA;
121cout<<"a:"<<endl<<a;
122TMatrix<r_8> b(B,false);
123cout<<"Matrices BBB*=D"<<endl;
124{for(int i=0;i<BBB.NRows();i++) for(int j=0;j<D.NCols();j++)
125 {b(i,j) = 0; for(int k=0;k<BBB.NCols();k++) b(i,j) += BBB(i,k)*D(k,j);}}
126BBB *= D;
127cout<<"B:"<<endl<<BBB;
128cout<<"b:"<<endl<<b;
129
130//-----------------------------------------------
131AA.Clone(A);
132cout<<endl<<"Matrices AA = AA + 10"<<endl;
133AA = AA + 10.; cout<<"AA"<<endl<<AA;
134cout<<endl<<"Matrices AA = AA - 10"<<endl;
135AA = AA - 10.; cout<<"AA"<<endl<<AA;
136cout<<endl<<"Matrices AA = 10 - AA"<<endl;
137AA = 10. - AA; cout<<"AA"<<endl<<AA;
138cout<<endl<<"Matrices AA = AA - 10"<<endl;
139AA = AA - 10.; cout<<"AA"<<endl<<AA;
140cout<<endl<<"Matrices AA = -1 * AA"<<endl;
141AA = -1. * AA; cout<<"AA"<<endl<<AA;
142cout<<endl<<"Matrices AA = 10 * AA"<<endl;
143AA = 10. * AA; cout<<"AA"<<endl<<AA;
144cout<<endl<<"Matrices AA = AA * 10"<<endl;
145AA = AA * 10.; cout<<"AA"<<endl<<AA;
146cout<<endl<<"Matrices AA = AA / 100"<<endl;
147AA = AA / 100.; cout<<"AA"<<endl<<AA;
148
149//-----------------------------------------------
150TMatrix<r_8> R;
151AA.Clone(A); AA += 10.; AAA.Clone(A); AAA += 100.;
152cout<<endl<<"Matrices R = A + AA"<<endl;
153R = A + AA; cout<<"R"<<endl<<R;
154cout<<endl<<"Matrices R = AA - A"<<endl;
155R = AA - A; cout<<"R"<<endl<<R;
156cout<<endl<<"Matrices R = A + AA + AAA"<<endl;
157R = A + AA + AAA; cout<<"R"<<endl<<R;
158cout<<endl<<"Matrices R = A + 100 + 2*A"<<endl;
159R = A + 100. + 2.*A; cout<<"R"<<endl<<R;
160
161//-----------------------------------------------
162TMatrix<r_8> RR(2,4);
163{for(int i=0;i<A.NRows();i++) for(int j=0;j<E.NCols();j++)
164 {RR(i,j) = 0; for(int k=0;k<A.NCols();k++) RR(i,j) += A(i,k)*E(k,j);}}
165cout<<endl<<"Matrices R = A * E"<<endl;
166R = A * E;
167cout<<"R"<<endl<<R; cout<<"RR"<<endl<<RR;
168
169//-----------------------------------------------
170cout<<endl<<"Matrices A = A.Transpose 2x"<<endl;
171cout<<"A"<<endl<<A;
172A = A.Transpose(); cout<<"trA"<<endl<<A;
173A = A.Transpose(); cout<<"trtrA"<<endl<<A;
174cout<<endl<<"Matrices AT = A.Transpose() 2x"<<endl;
175TMatrix<r_8> AT;
176AT = A.Transpose(); cout<<"AT"<<endl<<AT;
177AT = AT.Transpose(); cout<<"trAT"<<endl<<AT;
178
179//-----------------------------------------------
180cout<<endl<<"Test Inversion avec couplage a M=Matrix(C)"<<endl;
181TMatrix<r_8> X(10,10);
182{for(int i=0;i<10;i++) for(int j=0;j<10;j++)
183 {X(i,j) = drand01(); if(drand01()>0.8) X(i,j) += 1.e+15*drand01();}}
184cout<<"TMatrix X"<<endl<<X;
185{
186Matrix M(X); cout<<"Matrix M"<<endl<<M<<endl;
187Matrix MI = M.Inverse(); cout<<"MI"<<endl<<MI;
188MI *= M; cout<<"MI*M"<<endl<<MI;
189r_8 xmin=-1.;
190for(int i=0;i<10;i++) for(int j=0;j<10;j++)
191 if(i!=j && fabs(MI(i,j))>xmin) xmin=fabs(MI(i,j));
192cout<<"Biggest off diagonal identity matrix element is "<<xmin<<endl;
193} // destruction de M,MI
194cout<<"TMatrix X"<<endl<<X;
195
196//-----------------------------------------------
197{
198cout<<endl<<"Test Inversion directe"<<endl;
199cout<<"TMatrix X"<<endl<<X;
200TMatrix<r_8> Xinv;
201Xinv = X.Inverse();
202cout<<"TMatrix Xinv"<<endl<<Xinv;
203Xinv *= X;
204cout<<"Xinv *= X"<<endl<<Xinv;
205r_8 xmin=-1.;
206for(int i=0;i<10;i++) for(int j=0;j<10;j++)
207 if(i!=j && fabs(Xinv(i,j))>xmin) xmin=fabs(Xinv(i,j));
208cout<<"Biggest off diagonal identity matrix element is "<<xmin<<endl;
209cout<<"TMatrix X"<<endl<<X;
210}
211
212//-----------------------------------------------
213cout<<endl<<"Test liens TMatrix L avec Matrix MI"<<endl;
214Matrix MI(10,5);
215{for(int i=0;i<10;i++) for(int j=0;j<5;j++) MI(i,j) = 1000*i+j;}
216cout<<"MI"<<endl<<MI;
217{
218TMatrix<r_8> L(MI.NRows(),MI.NCol(),MI.Data(),new Bridge);
219cout<<"L"<<endl<<L;
220L *= 100.; cout<<"L*=100."<<endl<<L;
221} // destruction de L
222cout<<"MI(4,4)="<<MI(4,4)<<endl;
223
224} // destruction de toutes les matrices
225exit(0);
226}
Note: See TracBrowser for help on using the repository browser.