Changeset 299 in Sophya for trunk/SophyaLib/NTools/tmatrix.cc
- Timestamp:
- May 17, 1999, 7:16:44 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/NTools/tmatrix.cc
r291 r299 1 // $Id: tmatrix.cc,v 1. 4 1999-05-05 05:51:54ansari Exp $1 // $Id: tmatrix.cc,v 1.5 1999-05-17 17:16:43 ansari Exp $ 2 2 // C.Magneville 04/99 3 3 #include "machdefs.h" … … 9 9 #include "tmatrix.h" 10 10 #include "objfio.h" 11 #include "generalfit.h" 11 12 12 13 using namespace PlanckDPC; … … 130 131 { 131 132 if(mNr!=b.mNr || mNc!=b.mNc) 132 throw(SzMismatchError(" NDataBlockoperator C=A+B size mismatch\n"));133 throw(SzMismatchError("TMatrix operator C=A+B size mismatch\n")); 133 134 TMatrix<T> result; result.SetTemp(true); result.mNr=mNr; result.mNc=mNc; 134 135 result.mNDBlock = mNDBlock+b.mNDBlock; … … 139 140 { 140 141 if(mNr!=b.mNr || mNc!=b.mNc) 141 throw(SzMismatchError(" NDataBlockoperator C=A-B size mismatch\n"));142 throw(SzMismatchError("TMatrix operator C=A-B size mismatch\n")); 142 143 TMatrix<T> result; result.SetTemp(true); result.mNr=mNr; result.mNc=mNc; 143 144 result.mNDBlock = mNDBlock-b.mNDBlock; … … 149 150 { 150 151 if(mNr==0 || mNc==0 || b.mNc==0 || mNc!=b.mNr) 151 throw(SzMismatchError(" NDataBlockoperator C=A*B size mismatch\n"));152 throw(SzMismatchError("TMatrix operator C=A*B size mismatch\n")); 152 153 TMatrix<T> r; r.SetTemp(true); r.ReSize(mNr,b.mNc); 153 154 T *ai,*aik,*bj,*bkj,*ri,*rij; … … 160 161 } 161 162 return r; 163 } 164 165 #include "matrix.h" 166 //////////////////////////////////////////////////////////////// 167 //**** Pour inversion 168 TMatrix<r_8> TMatrix<r_8>::Inverse() const 169 // Inversion 170 { 171 TMatrix<r_8> b(mNc,mNr); 172 TMatrix<r_8> a(*this); 173 b = 1.; 174 if (fabs(TMatrix<r_8>::GausPiv(a,b)) < 1.e-50) 175 throw(MathExc("TMatrix Inverse() Singular Matrix")); 176 return b; 177 } 178 179 double TMatrix<r_8>::GausPiv(TMatrix<r_8>& a, TMatrix<r_8>& b) 180 // Pivot de Gauss 181 { 182 Matrix A(a); 183 Matrix B(b); 184 return Matrix::GausPiv(A,B); 185 } 186 187 ////////////////////////////////////////////////////////// 188 //**** Residus des fits 189 TMatrix<r_8> TMatrix<r_8>::FitResidus(GeneralFit& gfit) 190 // Retourne une classe contenant les residus du fit ``gfit''. 191 // On suppose que x=j (colonnes) et y=i (lignes) pour m(i,j). 192 { 193 if(NCols()<=0||NRows()<=0) 194 throw(SzMismatchError("TMatrix::FitResidus size mismatch\n")); 195 GeneralFunction* f = gfit.GetFunction(); 196 if(f==NULL) 197 throw(NullPtrError("TMatrix::FitResidus GeneraFit==NULL\n")); 198 int npar = gfit.GetNPar(); 199 if(npar==0) 200 throw(SzMismatchError("TMatrix::FitResidus GeneraFit 0 parametre\n")); 201 double* par = new double[npar]; 202 {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);} 203 TMatrix<r_8> m(*this); 204 for(int i=0;i<NRows();i++) for(int j=0;j<NCols();j++) { 205 double x[2] = {(double)j,(double)i}; // attention x=col y=row!! 206 m(i,j) -= f->Value(x,par); 207 } 208 delete [] par; 209 return m; 210 } 211 212 TMatrix<r_8> TMatrix<r_8>::FitFunction(GeneralFit& gfit) 213 // Retourne une classe contenant la fonction du fit ``gfit''. 214 // On suppose que x=j (colonnes) et y=i (lignes) pour m(i,j). 215 { 216 if(NCols()<=0||NRows()<=0) 217 throw(SzMismatchError("TMatrix::FitFunction size mismatch\n")); 218 GeneralFunction* f = gfit.GetFunction(); 219 if(f==NULL) 220 throw(NullPtrError("TMatrix::FitFunction GeneraFit==NULL\n")); 221 int npar = gfit.GetNPar(); 222 if(npar==0) 223 throw(SzMismatchError("TMatrix::FitFunction GeneraFit 0 parametre\n")); 224 double* par = new double[npar]; 225 {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);} 226 TMatrix<r_8> m(*this); 227 for(int i=0;i<NRows();i++) for(int j=0;j<NCols();j++) { 228 double x[2] = {(double)j,(double)i}; 229 m(i,j) = f->Value(x,par); 230 } 231 delete [] par; 232 return m; 162 233 } 163 234 … … 235 306 os.Put(itab,3); 236 307 // On ecrit le NDataBlock 237 //cmv encore des problemes avec les consteries238 308 FIO_NDataBlock<T> fio_nd(&dobj->DataBlock()); 239 309 fio_nd.Write(os);
Note:
See TracChangeset
for help on using the changeset viewer.