Changeset 299 in Sophya for trunk/SophyaLib


Ignore:
Timestamp:
May 17, 1999, 7:16:44 PM (26 years ago)
Author:
ansari
Message:

TMatrix et TVector suite cmv 17/5/99

Location:
trunk/SophyaLib/NTools
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/NTools/tmatrix.cc

    r291 r299  
    1 // $Id: tmatrix.cc,v 1.4 1999-05-05 05:51:54 ansari Exp $
     1// $Id: tmatrix.cc,v 1.5 1999-05-17 17:16:43 ansari Exp $
    22//                         C.Magneville          04/99
    33#include "machdefs.h"
     
    99#include "tmatrix.h"
    1010#include "objfio.h"
     11#include "generalfit.h"
    1112
    1213using namespace PlanckDPC;
     
    130131{
    131132if(mNr!=b.mNr || mNc!=b.mNc)
    132     throw(SzMismatchError("NDataBlock operator C=A+B size mismatch\n"));
     133    throw(SzMismatchError("TMatrix operator C=A+B size mismatch\n"));
    133134TMatrix<T> result; result.SetTemp(true); result.mNr=mNr; result.mNc=mNc;
    134135result.mNDBlock = mNDBlock+b.mNDBlock;
     
    139140{
    140141if(mNr!=b.mNr || mNc!=b.mNc)
    141     throw(SzMismatchError("NDataBlock operator C=A-B size mismatch\n"));
     142    throw(SzMismatchError("TMatrix operator C=A-B size mismatch\n"));
    142143TMatrix<T> result; result.SetTemp(true); result.mNr=mNr; result.mNc=mNc;
    143144result.mNDBlock = mNDBlock-b.mNDBlock;
     
    149150{
    150151if(mNr==0 || mNc==0 || b.mNc==0 || mNc!=b.mNr)
    151   throw(SzMismatchError("NDataBlock operator C=A*B size mismatch\n"));
     152  throw(SzMismatchError("TMatrix operator C=A*B size mismatch\n"));
    152153TMatrix<T> r; r.SetTemp(true); r.ReSize(mNr,b.mNc);
    153154T *ai,*aik,*bj,*bkj,*ri,*rij;
     
    160161}
    161162return r;
     163}
     164
     165#include "matrix.h"
     166////////////////////////////////////////////////////////////////
     167//**** Pour inversion
     168TMatrix<r_8> TMatrix<r_8>::Inverse() const
     169// Inversion
     170{
     171TMatrix<r_8> b(mNc,mNr);
     172TMatrix<r_8> a(*this);
     173b = 1.;
     174if (fabs(TMatrix<r_8>::GausPiv(a,b)) < 1.e-50)
     175  throw(MathExc("TMatrix Inverse() Singular Matrix"));
     176return b;
     177}
     178
     179double TMatrix<r_8>::GausPiv(TMatrix<r_8>& a, TMatrix<r_8>& b)
     180// Pivot de Gauss
     181{
     182Matrix A(a);
     183Matrix B(b);
     184return Matrix::GausPiv(A,B);
     185}
     186
     187//////////////////////////////////////////////////////////
     188//**** Residus des fits
     189TMatrix<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{
     193if(NCols()<=0||NRows()<=0)
     194  throw(SzMismatchError("TMatrix::FitResidus size mismatch\n"));
     195GeneralFunction* f = gfit.GetFunction();
     196if(f==NULL)
     197  throw(NullPtrError("TMatrix::FitResidus GeneraFit==NULL\n"));
     198int npar =  gfit.GetNPar();
     199if(npar==0)
     200  throw(SzMismatchError("TMatrix::FitResidus GeneraFit 0 parametre\n"));
     201double* par = new double[npar];
     202{for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);}
     203TMatrix<r_8> m(*this);
     204for(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}
     208delete [] par;
     209return m;
     210}
     211
     212TMatrix<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{
     216if(NCols()<=0||NRows()<=0)
     217  throw(SzMismatchError("TMatrix::FitFunction size mismatch\n"));
     218GeneralFunction* f = gfit.GetFunction();
     219if(f==NULL)
     220  throw(NullPtrError("TMatrix::FitFunction GeneraFit==NULL\n"));
     221int npar =  gfit.GetNPar();
     222if(npar==0)
     223  throw(SzMismatchError("TMatrix::FitFunction GeneraFit 0 parametre\n"));
     224double* par = new double[npar];
     225{for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);}
     226TMatrix<r_8> m(*this);
     227for(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}
     231delete [] par;
     232return m;
    162233}
    163234
     
    235306os.Put(itab,3);
    236307// On ecrit le NDataBlock
    237 //cmv   encore des problemes avec les consteries
    238308FIO_NDataBlock<T> fio_nd(&dobj->DataBlock());
    239309fio_nd.Write(os);
  • trunk/SophyaLib/NTools/tmatrix.h

    r288 r299  
    1010#include "anydataobj.h"
    1111#include "ndatablock.h"
     12class GeneralFit;
    1213
    1314namespace PlanckDPC {
     
    9394  TMatrix<T> Mul(const TMatrix<T>& b) const;
    9495
     96  // Pivot de Gauss : diagonalise la matrice A, en effectuant les memes
     97  // operations sur la matrice B
     98  TMatrix<T> Inverse() const;
     99  static T GausPiv(TMatrix<T>& A, TMatrix<T>& B);
     100
     101  // Residus et fonction fittees.
     102  TMatrix<T> FitResidus(GeneralFit& gfit);
     103  TMatrix<T> FitFunction(GeneralFit& gfit);
     104
    95105protected:
    96106  // partage les donnees si "a" temporaire, clone sinon.
Note: See TracChangeset for help on using the changeset viewer.