Changeset 975 in Sophya for trunk/SophyaProg


Ignore:
Timestamp:
Apr 27, 2000, 7:52:13 PM (25 years ago)
Author:
ansari
Message:

cm 27/4/00

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaProg/Tests/tsttminv.cc

    r934 r975  
    1818
    1919#if defined(COMPLEX)
    20 #define ABS_VAL(_x_) sqrt((double)(_x_.real()*_x_.real() + _x_.imag()*_x_.imag()))
    21 #if defined(PRECIS32)
    22 #define TYPE complex<r_4>
     20  #define ABS_VAL(_x_) sqrt((double)((_x_).real()*(_x_).real() + (_x_).imag()*(_x_).imag()))
     21  #if defined(PRECIS32)
     22    #define TYPE complex<r_4>
     23  #else
     24    #define TYPE complex<r_8>
     25  #endif
    2326#else
    24 #define TYPE complex<r_8>
    25 #endif
    26 #else
    27 #define ABS_VAL(_x_) fabs((double)_x_)
    28 #if defined(PRECIS32)
    29 #define TYPE r_4
    30 #else
    31 #define TYPE r_8
    32 #endif
     27  #define ABS_VAL(_x_) fabs((double)_x_)
     28  #if defined(PRECIS32)
     29    #define TYPE r_4
     30  #else
     31    #define TYPE r_8
     32  #endif
    3333#endif
    3434
     
    3737//--------------------------------------------------------
    3838// number of lines/columns
    39 int_4 N = 5;
     39uint_4 N = 5;
    4040// scale of the value (if =1 values between -1 and 1)
    4141r_8 scale = 1.;
    4242// number of values change by +/- vbig
    43 int_4 nbig = N;
     43uint_4 nbig = N;
    4444r_8 vbig = 1000.;
    45 // Nombre de ligne de matrice a imprimer
    46  int_4 nprline = 10;
     45// Nombre de lignes de matrice a imprimer
     46uint_4 nprline = 10;
     47// Initialisation du pauvre de l'aleatoire
     48 uint_4 nalea = 0;
    4749//--------------------------------------------------------
    4850
    4951//-- Decodage arguments
    5052char c;
    51 while((c = getopt(narg,arg,"hv:l:")) != -1) {
     53while((c = getopt(narg,arg,"hv:l:a:")) != -1) {
    5254  switch (c) {
    5355  case 'v' :
     
    5759    sscanf(optarg,"%d",&nprline);
    5860    break;
     61  case 'a' :
     62    sscanf(optarg,"%d",&nalea);
     63    break;
    5964  case 'h' :
    60     cout<<"tsttminv [-h] [-v N,scale,nbig,vbig] [-l nprline]"<<endl;
     65    cout<<"tsttminv [-h] [-v N,scale,nbig,vbig] [-l nprline] [-a nalea]"<<endl;
    6166    cout<<"matrix filled with : {[-1,1] +/- vbig(nbig time)}*scale"<<endl;
    6267    exit(-1);
     
    6469}
    6570if(N<=1) N = 1;
    66 cout<<"Taille matrice N = "<<N<<endl;
    67 cout<<"Elements entre +/- "<<scale<<endl;
    68 cout<<"Nombre de valeurs hors standard "<<nbig<<endl;
    69 cout<<"Valeurs hors standard v = v*(+/- "<<vbig<<" )"<<endl;
     71cout<<"Taille matrice NxN, N = "<<N<<endl;
     72cout<<"Elements entre +/- scale = "<<scale<<endl;
     73cout<<"Nombre de valeurs hors standard nbig = "<<nbig<<endl;
     74cout<<"Valeurs hors standard (+/- vbig = "<<vbig<<" ) * scale"<<endl;
    7075cout<<"Nombre de lignes de matrice a imprimer "<<nprline<<endl;
     76cout<<"Initialisation de l aleatoire par "<<nalea<<" tirages"<<endl;
    7177cout<<endl;
    7278
     
    8086TMatrix< TYPE > B(N,N);
    8187TMatrix< TYPE > C(N,N);
     88TVector< int >  Vind(N*N);
    8289A.Show();
    8390
    8491//-- Mise a zero
    85 A = (TYPE) 0;
     92A    = (TYPE) 0;
    8693InvA = (TYPE) 0;
    87 AiA = (TYPE) 0;
    88 B = (TYPE) 0;
    89 C = (TYPE) 0;
     94AiA  = (TYPE) 0;
     95B    = (TYPE) 0;
     96C    = (TYPE) 0;
    9097BaseArray::SetMaxPrint(nprline*N,0);
    9198
    9299//-- Fill matrices
    93100uint_8 k;
    94 int_4 i,j; double s;
     101uint_4 i,j; double s;
     102uint_4 nbr=0, nbi=0;
     103Vind = 0;
     104if(nalea>0) for(i=0;i<nalea;i++) drand01();
    95105A = Sequence(RandomSequence(RandomSequence::Flat,0.,1.));
    96 if(nbig>0) for(i=0;i<nbig;i++)
    97   {k=(uint_8)(drand01()*N*N); if(k>=N*N) k--;
    98    s=(drand01()>0.5)?1.:-1.; A[k] += (TYPE) s*vbig;}
     106if(nbig>0) for(i=0;i<nbig;i++) {
     107  k=(uint_8)(drand01()*N*N); if(k>=N*N) k--;
     108  s=(drand01()>0.5)?1.:-1.;
     109  if(Vind[k]==0) {A[k] += (TYPE) s*vbig; Vind[k]=1; nbr++;}
     110}
    99111A *= (TYPE) scale;
    100112#if defined(COMPLEX)
     113Vind = 0;
    101114B = Sequence(RandomSequence(RandomSequence::Flat,0.,1.));
    102 if(nbig>0) for(i=0;i<nbig;i++)
    103   {k=(uint_8)(drand01()*N*N); if(k>=N*N) k--;
    104    s=(drand01()>0.5)?1.:-1.; B[k] += (TYPE) s*vbig;}
     115if(nbig>0) for(i=0;i<nbig;i++) {
     116  k=(uint_8)(drand01()*N*N); if(k>=N*N) k--;
     117  s=(drand01()>0.5)?1.:-1.;
     118  if(Vind[k]==0) {B[k] += (TYPE) s*vbig; Vind[k]=1; nbi++;}
     119}
    105120B *= (TYPE) scale;
    106121A += TYPE(0.,1.)*B;
    107122#endif
     123cout<<"Nombre de valeurs BIG reelles = "<<nbr<<", imaginaires = "<<nbi<<endl;
    108124
    109125//-- Print matrice A
     
    112128
    113129//-- Inversion
    114 cout<<"Inversion"<<endl;
     130cout<<"------------ Inversion"<<endl;
    115131InvA = Inverse(A);
    116132cout<<"------------ TMatrix InvA = A^(-1):"<<endl;
     
    124140
    125141//-- Check
    126 double vmin,vmax;
    127 k = 0;
    128 for(int i=0;i<N;i++) {
    129   double absv = ABS_VAL( AiA(i,i) );
    130   if(k==0) {vmin = vmax = absv; k++; continue;}
     142double vmax=-1.;
     143for(i=0;i<N;i++) {
     144  double absv = ABS_VAL( 1. - AiA(i,i) );
    131145  if( absv > vmax ) vmax = absv;
    132   if( absv < vmin ) vmin = absv;
    133   k++;
    134146}
    135 cout<<"Limites sur la diagonale  "
    136     <<vmin<<" , "<<vmax<<"  n="<<k<<endl;
    137 k = 0;
    138 for(int i=0;i<N;i++) for(int j=0;j<N;j++) {
     147cout<<"Ecart maximum par rapport a 1 sur diagonale = "<<vmax<<endl;
     148vmax = -1.;
     149for(i=0;i<N;i++) for(j=0;j<N;j++) {
    139150  if( i == j ) continue;
    140151  double absv = ABS_VAL( AiA(i,j) );
    141   if(k==0) {vmin = vmax = absv; k++; continue;}
    142152  if( absv > vmax ) vmax = absv;
    143   if( absv < vmin ) vmin = absv;
    144   k++;
    145153}
    146 cout<<"Limites hors diagonale  "
    147     <<vmin<<" , "<<vmax<<"  n="<<k<<endl;
     154cout<<"Ecart maximum par rapport a 0 hors diagonale = "<<vmax<<endl;
    148155
    149156exit(0);
Note: See TracChangeset for help on using the changeset viewer.