Changeset 975 in Sophya for trunk/SophyaProg
- Timestamp:
- Apr 27, 2000, 7:52:13 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaProg/Tests/tsttminv.cc
r934 r975 18 18 19 19 #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 23 26 #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 33 33 #endif 34 34 … … 37 37 //-------------------------------------------------------- 38 38 // number of lines/columns 39 int_4 N = 5;39 uint_4 N = 5; 40 40 // scale of the value (if =1 values between -1 and 1) 41 41 r_8 scale = 1.; 42 42 // number of values change by +/- vbig 43 int_4 nbig = N;43 uint_4 nbig = N; 44 44 r_8 vbig = 1000.; 45 // Nombre de ligne de matrice a imprimer 46 int_4 nprline = 10; 45 // Nombre de lignes de matrice a imprimer 46 uint_4 nprline = 10; 47 // Initialisation du pauvre de l'aleatoire 48 uint_4 nalea = 0; 47 49 //-------------------------------------------------------- 48 50 49 51 //-- Decodage arguments 50 52 char c; 51 while((c = getopt(narg,arg,"hv:l: ")) != -1) {53 while((c = getopt(narg,arg,"hv:l:a:")) != -1) { 52 54 switch (c) { 53 55 case 'v' : … … 57 59 sscanf(optarg,"%d",&nprline); 58 60 break; 61 case 'a' : 62 sscanf(optarg,"%d",&nalea); 63 break; 59 64 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; 61 66 cout<<"matrix filled with : {[-1,1] +/- vbig(nbig time)}*scale"<<endl; 62 67 exit(-1); … … 64 69 } 65 70 if(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;71 cout<<"Taille matrice NxN, N = "<<N<<endl; 72 cout<<"Elements entre +/- scale = "<<scale<<endl; 73 cout<<"Nombre de valeurs hors standard nbig = "<<nbig<<endl; 74 cout<<"Valeurs hors standard (+/- vbig = "<<vbig<<" ) * scale"<<endl; 70 75 cout<<"Nombre de lignes de matrice a imprimer "<<nprline<<endl; 76 cout<<"Initialisation de l aleatoire par "<<nalea<<" tirages"<<endl; 71 77 cout<<endl; 72 78 … … 80 86 TMatrix< TYPE > B(N,N); 81 87 TMatrix< TYPE > C(N,N); 88 TVector< int > Vind(N*N); 82 89 A.Show(); 83 90 84 91 //-- Mise a zero 85 A = (TYPE) 0;92 A = (TYPE) 0; 86 93 InvA = (TYPE) 0; 87 AiA = (TYPE) 0;88 B = (TYPE) 0;89 C = (TYPE) 0;94 AiA = (TYPE) 0; 95 B = (TYPE) 0; 96 C = (TYPE) 0; 90 97 BaseArray::SetMaxPrint(nprline*N,0); 91 98 92 99 //-- Fill matrices 93 100 uint_8 k; 94 int_4 i,j; double s; 101 uint_4 i,j; double s; 102 uint_4 nbr=0, nbi=0; 103 Vind = 0; 104 if(nalea>0) for(i=0;i<nalea;i++) drand01(); 95 105 A = 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;} 106 if(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 } 99 111 A *= (TYPE) scale; 100 112 #if defined(COMPLEX) 113 Vind = 0; 101 114 B = 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;} 115 if(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 } 105 120 B *= (TYPE) scale; 106 121 A += TYPE(0.,1.)*B; 107 122 #endif 123 cout<<"Nombre de valeurs BIG reelles = "<<nbr<<", imaginaires = "<<nbi<<endl; 108 124 109 125 //-- Print matrice A … … 112 128 113 129 //-- Inversion 114 cout<<" Inversion"<<endl;130 cout<<"------------ Inversion"<<endl; 115 131 InvA = Inverse(A); 116 132 cout<<"------------ TMatrix InvA = A^(-1):"<<endl; … … 124 140 125 141 //-- 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;} 142 double vmax=-1.; 143 for(i=0;i<N;i++) { 144 double absv = ABS_VAL( 1. - AiA(i,i) ); 131 145 if( absv > vmax ) vmax = absv; 132 if( absv < vmin ) vmin = absv;133 k++;134 146 } 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++) { 147 cout<<"Ecart maximum par rapport a 1 sur diagonale = "<<vmax<<endl; 148 vmax = -1.; 149 for(i=0;i<N;i++) for(j=0;j<N;j++) { 139 150 if( i == j ) continue; 140 151 double absv = ABS_VAL( AiA(i,j) ); 141 if(k==0) {vmin = vmax = absv; k++; continue;}142 152 if( absv > vmax ) vmax = absv; 143 if( absv < vmin ) vmin = absv;144 k++;145 153 } 146 cout<<"Limites hors diagonale " 147 <<vmin<<" , "<<vmax<<" n="<<k<<endl; 154 cout<<"Ecart maximum par rapport a 0 hors diagonale = "<<vmax<<endl; 148 155 149 156 exit(0);
Note:
See TracChangeset
for help on using the changeset viewer.