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