source: Sophya/trunk/SophyaProg/Tests/tsttvec.cc@ 3076

Last change on this file since 3076 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

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