#include "machdefs.h"
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "outilsinit.h"
#include "pexceptions.h"
#include "cvector.h"
#include "tvector.h"
#include "nbrandom.h"

////////////////////////////////////////////////////////////////////////////////////////
int main(int narg,char *arg[])
{
PeidaInit();
r_8 v[10] = {1,2,3,4,5,6,7,8,9,10};
{
cout<<"TVector(10)"<<endl;
TVector<r_8> v1(10);
{for(int i=0;i<10;i++) v1(i)=100+i;}
cout<<"nel="<<v1.NElts()<<endl<<v1;

{
cout << " Test ecriture PPersist TVector " << endl; 
FIO_TVector<r_8> ftv(v1);
ftv.Write("tvec.ppf");
}
{
cout << " Test lecture PPersist TVector " << endl; 
FIO_TVector<r_8> ftv("tvec.ppf");
cout<<"Vlue:"<<(TVector<r_8>)ftv<<endl;
}


cout<<"TVector(10,v,br)"<<endl;
TVector<r_8> v2(10,v,new Bridge); cout<<v2;

cout<<"TVector()"<<endl;
TVector<r_8> v3; cout<<v3;

cout<<"v3 = v1"<<endl;
v3 = v1; cout<<v3;

cout<<"v3 = 123456"<<endl;
v3 = 123456.; cout<<v3;

cout<<"ps = v1 * v2"<<endl;
r_8 ps = v1 * v2; cout<<"ps="<<ps<<endl;

cout<<"v2 = 10.*v1"<<endl;
v2 = 10.*v1; cout<<v2;
cout<<"v2 = v2*0.1"<<endl;
v2 = v2*0.1; cout<<v2;

cout<<"v2 = v1/10."<<endl;
v2 = v1/10.; cout<<v2;
cout<<"v2 = v2/0.1"<<endl;
v2 = v2/0.1; cout<<v2;

cout<<"v2 = 10.+v1"<<endl;
v2 = 10.+v1; cout<<v2;
cout<<"v2 = v2-10."<<endl;
v2 = v2-10.; cout<<v2;

cout<<"v2 = 10.-v1"<<endl;
v2 = 10.-v1; cout<<v2;
cout<<"v2 = (-1.)*v2+10."<<endl;
v2 = (-1.)*v2+10.; cout<<v2;

cout<<"v2 += 10."<<endl;
v2 += 10.; cout<<v2;
cout<<"v2 -= 10."<<endl;
v2 -= 10.; cout<<v2;
cout<<"v2 *= 10."<<endl;
v2 *= 10.; cout<<v2;
cout<<"v2 /= 10."<<endl;
v2 /= 10.; cout<<v2;

cout<<"v3.ReSize(4)"<<endl;
v3.ReSize(4);
{for(int i=0;i<4;i++) v3(i)=i+1;} cout<<v3;
TMatrix<r_8> M(2,4);
{for(int i=0;i<8;i++) M[i]=i+1;} cout<<M;
TVector<r_8> v4(10);
v4 = M*v3; cout<<v4;

cout<<"LinSolve(A,B,X)"<<endl;
TMatrix<r_8> A(5,5);
TVector<r_8> B(5);
{for(int i=0;i<25;i++) {A[i]=drand01(); if(i<5) B(i)=drand01();}}
TVector<r_8> X;
X = B;
cout<<"A = "<<A; cout<<"B = "<<B;
r_8 d=0.;
d = LinSolve(A,B,X);
cout<<"d="<<d<<endl; cout<<"X = "<<X;
X = A*X; cout<<"A*X = "<<X;
X -= B; cout<<"B-X = "<<X;
cout<<"LinSolveInPlace(A,B)"<<endl;
X = B;
d = LinSolveInPlace(A,X);
cout<<"d="<<d<<endl; cout<<"X = "<<X;

cout<<"Conversion en ancien Vector"<<endl;
Vector Vold(v1);
cout<<"Vold = "<<Vold;

} // destruction de toutes les vecteurs
exit(0);
}
