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 "ntoolsinit.h"
|
---|
8 | #include "pexceptions.h"
|
---|
9 |
|
---|
10 | #include "array.h"
|
---|
11 | #include "srandgen.h"
|
---|
12 |
|
---|
13 | ////////////////////////////////////////////////////////////////////////////////////////
|
---|
14 | int main(int narg,char *arg[])
|
---|
15 | {
|
---|
16 | SophyaInit();
|
---|
17 | r_8 v[10] = {1,2,3,4,5,6,7,8,9,10};
|
---|
18 | {
|
---|
19 | cout<<"TVector(10)"<<endl;
|
---|
20 | TVector<r_8> v1(10);
|
---|
21 | {for(int i=0;i<10;i++) v1(i)=100+i;}
|
---|
22 | cout<<"nel="<<v1.NElts()<<endl<<v1;
|
---|
23 |
|
---|
24 | {
|
---|
25 | cout << " Test ecriture PPersist TVector " << endl;
|
---|
26 | FIO_TArray<r_8> ftv(v1);
|
---|
27 | ftv.Write("tvec.ppf");
|
---|
28 | }
|
---|
29 | {
|
---|
30 | cout << " Test lecture PPersist TVector " << endl;
|
---|
31 | FIO_TArray<r_8> ftv("tvec.ppf");
|
---|
32 | cout<<"Vlue:"<<(TVector<r_8>)ftv<<endl;
|
---|
33 | }
|
---|
34 |
|
---|
35 |
|
---|
36 | cout<<"TVector(10,v,br) (v2)"<<endl;
|
---|
37 | sa_size_t siz[5];
|
---|
38 | siz[1] = 10;
|
---|
39 | siz[0] = 1;
|
---|
40 | TVector<r_8> v2(TArray<r_8>(2,siz,v,1,0,new Bridge)); cout<<v2;
|
---|
41 |
|
---|
42 | cout<<"TVector()"<<endl;
|
---|
43 | TVector<r_8> v3; cout<<v3;
|
---|
44 |
|
---|
45 | cout<<"v3 = v1"<<endl;
|
---|
46 | v3 = v1; cout<<v3;
|
---|
47 |
|
---|
48 | cout<<"v3 = 123456"<<endl;
|
---|
49 | v3 = 123456.; cout<<v3;
|
---|
50 |
|
---|
51 | cout<<"ps = v2.Transpose() * v1"<<endl;
|
---|
52 | r_8 ps = (v2.Transpose()*v1).toScalar(); cout<<"ps="<<ps<<endl;
|
---|
53 |
|
---|
54 | cout<<"v2 = 10.*v1"<<endl;
|
---|
55 | v2 = 10.*v1; cout<<v2;
|
---|
56 | cout<<"v2 = v2*0.1"<<endl;
|
---|
57 | v2 = v2*0.1; cout<<v2;
|
---|
58 |
|
---|
59 | cout<<"v2 = v1/10."<<endl;
|
---|
60 | v2 = v1/10.; cout<<v2;
|
---|
61 | cout<<"v2 = v2/0.1"<<endl;
|
---|
62 | v2 = v2/0.1; cout<<v2;
|
---|
63 |
|
---|
64 | cout<<"v2 = 10.+v1"<<endl;
|
---|
65 | v2 = 10.+v1; cout<<v2;
|
---|
66 | cout<<"v2 = v2-10."<<endl;
|
---|
67 | v2 = v2-10.; cout<<v2;
|
---|
68 |
|
---|
69 | cout<<"v2 = 10.-v1"<<endl;
|
---|
70 | v2 = 10.-v1; cout<<v2;
|
---|
71 | cout<<"v2 = (-1.)*v2+10."<<endl;
|
---|
72 | v2 = (-1.)*v2+10.; cout<<v2;
|
---|
73 |
|
---|
74 | cout<<"v2 += 10."<<endl;
|
---|
75 | v2 += 10.; cout<<v2;
|
---|
76 | cout<<"v2 -= 10."<<endl;
|
---|
77 | v2 -= 10.; cout<<v2;
|
---|
78 | cout<<"v2 *= 10."<<endl;
|
---|
79 | v2 *= 10.; cout<<v2;
|
---|
80 | cout<<"v2 /= 10."<<endl;
|
---|
81 | v2 /= 10.; cout<<v2;
|
---|
82 |
|
---|
83 | cout<<"v3.ReSize(4)"<<endl;
|
---|
84 | v3.ReSize(4);
|
---|
85 | {for(int i=0;i<4;i++) v3(i)=i+1;} cout<<v3;
|
---|
86 | TMatrix<r_8> M(2,4);
|
---|
87 | {for(int i=0;i<8;i++) M[i]=i+1;} cout<<M;
|
---|
88 | TVector<r_8> v4(10);
|
---|
89 | v4 = M*v3; cout<<v4;
|
---|
90 |
|
---|
91 | cout<<"LinSolve(A,B,X)"<<endl;
|
---|
92 | TMatrix<r_8> A(5,5);
|
---|
93 | TVector<r_8> B(5);
|
---|
94 | {for(int i=0;i<25;i++) {A[i]=drand01(); if(i<5) B(i)=drand01();}}
|
---|
95 | TVector<r_8> X;
|
---|
96 | X = B;
|
---|
97 | cout<<"A = "<<A; cout<<"B = "<<B;
|
---|
98 | r_8 d=0.;
|
---|
99 | d = LinSolve(A,B,X);
|
---|
100 | cout<<"d="<<d<<endl; cout<<"X = "<<X;
|
---|
101 | X = A*X; cout<<"A*X = "<<X;
|
---|
102 | X -= B; cout<<"B-X = "<<X;
|
---|
103 | cout<<"LinSolveInPlace(A,B)"<<endl;
|
---|
104 | X = B;
|
---|
105 | d = LinSolveInPlace(A,X);
|
---|
106 | cout<<"d="<<d<<endl; cout<<"X = "<<X;
|
---|
107 |
|
---|
108 | cout<<"Conversion en ancien Vector"<<endl;
|
---|
109 | Vector Vold(v1);
|
---|
110 | cout<<"Vold = "<<Vold;
|
---|
111 |
|
---|
112 | } // destruction de toutes les vecteurs
|
---|
113 | exit(0);
|
---|
114 | }
|
---|