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