Changeset 958 in Sophya for trunk/SophyaLib/NTools/poly.cc


Ignore:
Timestamp:
Apr 18, 2000, 3:38:53 PM (25 years ago)
Author:
ansari
Message:

doc + vire warning cmv 18/04/00

File:
1 edited

Legend:

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

    r938 r958  
    44#include "fioarr.h"
    55
    6 //++
    7 // Class        Poly
    8 // Lib          Outils++
    9 // include      poly.h
    10 //
    11 //      Classe de calcul sur polynômes à une variable.
    12 //--
    13 
    14 //++
    15 // Links        Parents
    16 // Vector
    17 //--
    18 
    19 //++
    20 // Titre        Constructeurs
    21 //--
    22 
    23 
    24 //////////////////////////////////////////////////////////////////////////
    25 //++
    26 // Poly::Poly(int degre=0)
    27 //
    28 //      Crée un nouveau polynôme, en allouant de la place pour
    29 //      le degré spécifié.
    30 //--
    31 
     6////////////////////////////////////////////////////////////
     7////////////////////////////////////////////////////////////
     8////////////////////////////////////////////////////////////
     9////////////////////////////////////////////////////////////
     10////////////////////////////////////////////////////////////
     11/*!
     12  \class SOPHYA::Poly
     13  \ingroup NTools
     14  One dimensional polynomials class.
     15*/
     16
     17//! Constructor
     18/*! Create a 1D polynomial of degre \b degre */
    3219Poly::Poly(int degre)
    3320: TVector<r_8>(degre+1), dirty(0), deg(0)
     
    3623}
    3724
    38 //++
     25//! Constructor by copy
    3926Poly::Poly(Poly const& a)
    40 //
    41 //      Constructeur par copie.
    42 //--
    4327:TVector<r_8>(a), dirty(a.dirty), deg(a.deg)
    4428{
     
    4630}
    4731
    48 
     32//! update degre
     33/*! update degre (that could be changed after operations) */
    4934void Poly::UpdateDeg() const
    5035{
     
    5641}
    5742
    58 //++
    59 // Titre        Méthodes
    60 //--
    61 
    62 //++
    63 // double& Poly::operator[](int i)
    64 //      Permet d'accéder au coefficient de degré i (avec version
    65 //      const).
    66 //--
    67 
    68 //++
     43//! compute value P(\b x)
    6944double Poly::operator()(double x) const
    70 //
    71 //      Calcule la valeur du polynôme au point x.
    72 //--
    7345{
    7446  UpdateDegIfDirty();
     
    8153}
    8254
    83 //++
     55//! Replace p(x) by its derivate
    8456void Poly::Derivate()
    85 //
    86 //      Remplace le polynôme par le polynôme dérivé.
    87 //--
    8857{
    8958  UpdateDegIfDirty();
     
    9665
    9766
    98 //++
     67//! Return the derivate in \b der(x)
    9968void Poly::Derivate(Poly& der) const
    100 //
    101 //      Retourne dans der le polynôme dérivé.
    102 //--
    10369{
    10470  UpdateDegIfDirty();
     
    11076
    11177
    112 //++
     78//! Return the roots of the polynomial into \b roots
     79/*!
     80  This works until degre 2
     81  \return the number of roots
     82*/
    11383int Poly::Roots(TVector<r_8>& roots) const
    114 //
    115 //      Retourne dans roots les racines réelles, si on sait
    116 //      les calculer. Retourne le nombre de racines.
    117 //--
    11884{
    11985  UpdateDegIfDirty();
     
    135101
    136102
    137 //++
     103//! Return root \b r for a degre 1 polynomial
     104/*! \return return 1 if succes, 0 if not */
    138105int Poly::Root1(double& r) const
    139 //
    140 //      Seulement si le polynôme est de degré 1: retourne
    141 //      la racine dans "r". Retourne 1 (nombre de racines).
    142 //--
    143106{
    144107  UpdateDegIfDirty();
     
    150113}
    151114
    152 //++
     115//! Return roots \b r1 and \b r2 for a degre 2 polynomial
     116/*! \return return the number of roots found */
    153117int Poly::Root2(double& r1, double& r2) const
    154 //
    155 //      Seulement si le polynôme est de degre 2: retourne
    156 //      les racines dans "r1" et "r2". Retourne 0, 1 ou 2
    157 //      (nombre de racines).
    158 //--
    159118{
    160119  UpdateDegIfDirty();
     
    172131}
    173132
    174 //++
     133//! Operator P(x) = a(x)
    175134Poly& Poly::operator = (Poly const& a)
    176 //
    177 //      Opérateur d'affectation.
    178 //--
    179135{
    180136  if (this == &a) return *this;
     
    185141}
    186142
    187 //++
    188 // Titres       Opérations sur polynômes
    189 //--
    190 
    191 //++
     143//! Perform P(x) += b(x)
    192144Poly& Poly::operator += (Poly const& b)
    193 //
    194 //--
    195145{
    196146  UpdateDegIfDirty();
     
    206156}
    207157
    208 //++
     158//! Perform P(x) -= b(x)
    209159Poly& Poly::operator -= (Poly const& b)
    210 //
    211 //--
    212160{
    213161  UpdateDegIfDirty();
     
    223171}
    224172
    225 //++
     173//! Perform P(x) *= b(x)
    226174Poly& Poly::operator *= (double a)
    227 //
    228 //--
    229175{
    230176  UpdateDegIfDirty();
     
    233179}
    234180
    235 //++
     181//! Return P(x) = *this(x) * b(x)
    236182Poly Poly::Mult(Poly const& b) const
    237 //
    238 //--
    239183{
    240184Poly c(deg + b.deg);
     
    254198}
    255199
    256 //++
     200//! Print on stream \b s
    257201void Poly::Print(ostream& s, int_4 , bool ) const
    258 //
    259 //      Impresssion.
    260 //--
    261202{
    262203  UpdateDegIfDirty();
     
    274215}
    275216
    276 //++
     217//! Fit datas by a polynomial
     218/*!
     219  Fit y(x) by a polynimial P(x)
     220  \param x : x datas
     221  \param y : y datas
     222  \param degre : degre of the polynomial P(x) to be fitted
     223  \warning result is stored in the current object
     224  \return return chisquare
     225*/
    277226double Poly::Fit(TVector<r_8> const& x, TVector<r_8> const& y, int degre)
    278 //
    279 //      Ajustement polynomial par moindre carrés. Un polynôme de
    280 //      degré "degre" est ajusté sur les données "x" et "y", et stocké dans
    281 //      l'objet courant. Retourne le chi2.
    282 //--
    283227{
    284228  int n = x.NElts();
     
    303247}
    304248
    305 //++
     249//! Fit datas with errors by a polynomial
     250/*!
     251  Fit y(x) by a polynimial P(x)
     252  \param x : x datas
     253  \param y : y datas
     254  \param erry2 : errors squared on y
     255  \param degre : degre of the polynomial P(x) to be fitted
     256  \warning result is stored in the current object
     257  \return \b errcoeff : errors on the coefficients
     258  \return return chisquare
     259*/
    306260double Poly::Fit(TVector<r_8> const& x, TVector<r_8> const& y,
    307261       TVector<r_8> const& erry2, int degre,TVector<r_8>& errCoef)
    308 //
    309 //      Ajustement polynomial par moindre carrés. Un polynôme de
    310 //      degré est ajusté sur les données x et y, et stocké dans
    311 //      l'objet courant. erry2 contient le carre des erreurs sur y.
    312 //      Retourne le chi2.
    313 //--
    314262{
    315263  int n = x.NElts();
     
    337285
    338286
    339 //++
    340 // Poly Poly::power(int n) const
    341 //
    342 //      Retourne le polynôme à la puissance n
    343 //--
    344 
     287//! Return the polynomial at power \b n : ( \f$ P(x)^n \f$ )
    345288Poly Poly::power(int n) const // a accelerer !!!
    346289{
     
    351294}
    352295
    353 //++
     296//! Substitue polynomial and return P\f$ (b(x)) \f$
    354297Poly Poly::operator() (Poly const& b) const
    355 //
    356 //      Substitution d'un polynôme dans un autre.
    357 //--
    358298{
    359299  Poly c(b.Degre()*Degre());
     
    365305
    366306//////////////////////////////////////////////////////////////////////////
     307//! For persistance management
    367308void ObjFileIO<Poly>::ReadSelf(PInPersist& is)
    368309{
     
    375316}
    376317
     318//! For persistance management
    377319void ObjFileIO<Poly>::WriteSelf(POutPersist& os) const
    378320{
     
    385327
    386328//////////////////////////////////////////////////////////////////////////
     329/*! \ingroup NTools
     330  \fn binomial(int,int)
     331  Return the binomial coefficient \f$ {C_n}^p \f$.
     332*/
    387333int binomial(int n, int p)
    388334{
     
    393339}
    394340
    395 //////////////////////////////////////////////////////////////////////////
    396 // ******************* POLY 2 VARIABLES ******************
    397 //++
    398 // Class        Poly2
    399 // Lib          Outils++
    400 // include      poly.h
    401 //
    402 //      Classe de calcul sur polynômes à deux variables.
    403 //--
    404 
    405 //++
    406 // Links        Parents
    407 // Vector
    408 //--
    409 
    410 //++
    411 // Titre        Constructeurs
    412 //--
    413 
    414 //++
     341
     342////////////////////////////////////////////////////////////
     343////////////////////////////////////////////////////////////
     344////////////////////////////////////////////////////////////
     345////////////////////////////////////////////////////////////
     346////////////////////////////////////////////////////////////
     347/*!
     348  \class SOPHYA::Poly2
     349  \ingroup NTools
     350  Two dimensional polynomials class.
     351*/
     352
     353//! Constructor of 2D polynomial of degres \b degreX \b degreY
    415354Poly2::Poly2(int degreX, int degreY)
    416 //
    417 //      Crée un polynôme de degrés partiels degreX et degreY.
    418 //--
    419355:TVector<r_8>((degreX+1)*(degreY+1)), dirty(0),
    420356 maxDegX(degreX), maxDegY(degreY), degX(0), degY(0), deg(0)
     
    423359}
    424360
    425 //++
     361//! Constructor of 2D polynomial \f$ P(x,y) = px(x) * py(y) \f$
    426362Poly2::Poly2(Poly const& polX, Poly const& polY)
    427 //
    428 //      Crée un polynôme à deux variables comme produit
    429 //      de deux polynômes à une variable, p2(x,y)=px(x)py(y)
    430 //--
    431363:TVector<r_8>((polX.Degre()+1)*(polY.Degre()+1)), dirty(0),
    432364 maxDegX(polX.Degre()), maxDegY(polY.Degre()),
     
    439371}
    440372
    441 //++
     373//! Constructor by copy
    442374Poly2::Poly2(Poly2 const& a)
    443 //
    444 //      Constructeur par copie.
    445 //--
    446375:TVector<r_8>(a), dirty(a.dirty),
    447376 maxDegX(a.maxDegX), maxDegY(a.maxDegY),
     
    451380}
    452381
    453 
    454 //++
    455 // Titre        Méthodes
    456 //--
    457 
    458 //++
     382//! Operator P(x) = a(x)
    459383Poly2& Poly2::operator = (Poly2 const& a)
    460 //
    461 //      Opérateur d'affectation.
    462 //--
    463384{
    464385  if (this == &a) return *this;
     
    475396}
    476397
    477 //++
     398//! Re-allocate space for 2D polynomial with partial degres \b degreX \b degreY
    478399void Poly2::Realloc(int degreX, int degreY)
    479 //
    480 //      Redimensionne le polynôme comme etant un
    481 //      polynôme de degrés partiels degreX et degreY.
    482 //--
    483400{
    484401  UpdateDegIfDirty();
     
    499416
    500417
     418//! update degres
     419/*! update degres (that could be changed after operations) */
    501420void Poly2::UpdateDeg() const
    502421{
     
    514433}
    515434
    516 //++
    517 // int Poly2::DegX() const
    518 //      Degré partiel en X.
    519 // int Poly2::DegY() const
    520 //      Degré partiel en Y
    521 // int Poly2::MaxDegX() const
    522 //      Degré partiel maximum (alloué) en X
    523 // int Poly2::MaxDegY() const
    524 //      Degré partiel maximum (alloué) en Y
    525 // int Poly2::Deg()  const
    526 //      Degré total.
    527 //--
    528 
    529 //++
    530 // double& Poly2::Coef(int dx, int dy)
    531 //      Retourne le coefficient de x^dx y^dy
    532 //      (avec aussi version const).
    533 //--
    534 
    535 //++
     435//! Return P(\b x, \b y)
    536436double Poly2::operator()(double x, double y) const
    537 //
    538 //      Retourne la valeur en (x,y).
    539 //--
    540437{
    541438  UpdateDegIfDirty();
     
    553450}
    554451
    555 //++
     452//! Fit datas by a polynomial
     453/*!
     454  Fit z(x,y) by a polynimial P(x,y)
     455  \param x : x datas
     456  \param y : y datas
     457  \param z : z datas
     458  \param degreX : partial degre on X
     459  \param degreY : partial degre on Y
     460  \warning result is stored in the current object
     461  \return return chisquare
     462*/
    556463double Poly2::Fit(TVector<r_8> const& x, TVector<r_8> const& y,
    557464                 TVector<r_8> const& z, int degreX, int degreY)
    558 //
    559 //      Ajustement par moindre carrés z = P(x,y), degrés partiels imposés.
    560 //--
    561465{
    562466  int n = x.NElts();
     
    586490}
    587491
    588 
    589 //++
     492//! Fit datas with errors by a polynomial
     493/*!
     494  Fit z(x,y) by a polynimial P(x,y)
     495  \param x : x datas
     496  \param y : y datas
     497  \param z : z datas
     498  \param errz2 : errors squared on z
     499  \param degreX : partial degre on X
     500  \param degreY : partial degre on Y
     501  \warning result is stored in the current object
     502  \return \b errcoeff : errors on the coefficients
     503  \return return chisquare
     504*/
    590505double Poly2::Fit(TVector<r_8> const& x, TVector<r_8> const& y, TVector<r_8> const& z,
    591506                  TVector<r_8> const& errz2, int degreX, int degreY,
    592507                  TVector<r_8>& errCoef)
    593 //
    594 //      Ajustement par moindre carrés z = P(x,y), degrés partiels imposés,
    595 //      et erreurs^2 sur z dans errz2.
    596 //--
    597508{
    598509  int n = x.NElts();
     
    624535}
    625536
    626 //++
     537//! Fit datas by a polynomial
     538/*!
     539  Fit z(x,y) by a polynimial P(x,y)
     540  \param x : x datas
     541  \param y : y datas
     542  \param z : z datas
     543  \param degre : total degre
     544  \warning result is stored in the current object
     545  \return return chisquare
     546*/
    627547double Poly2::Fit(TVector<r_8> const& x, TVector<r_8> const& y,
    628548                              TVector<r_8> const& z, int degre)
    629 //
    630 //      Ajustement par moindre carrés z = P(x,y), degré total imposé.
    631 //--
    632549{
    633550  int n = x.NElts();
     
    668585}
    669586
    670 
    671 //++
     587//! Fit datas with errors by a polynomial
     588/*!
     589  Fit z(x,y) by a polynimial P(x,y)
     590  \param x : x datas
     591  \param y : y datas
     592  \param z : z datas
     593  \param errz2 : errors squared on z
     594  \param degre : total degre
     595  \warning result is stored in the current object
     596  \return \b errcoeff : errors on the coefficients
     597  \return return chisquare
     598*/
    672599double Poly2::Fit(TVector<r_8> const& x, TVector<r_8> const& y,
    673600               TVector<r_8> const& z,TVector<r_8> const& errz2,
    674601                              int degre, TVector<r_8>& errCoef)
    675 //
    676 //      Ajustement par moindre carrés z = P(x,y), degré total imposé,
    677 //      et erreurs^2 sur z dans errz2.
    678 //--
    679602{
    680603  int n = x.NElts();
     
    721644}
    722645
    723 //++
     646//! Print on stream \b s
    724647void Poly2::Print(ostream& s, int_4 , bool ) const
    725 //
    726 //      Impression sur stream s.
    727 //--
    728648{
    729649  UpdateDegIfDirty();
     
    750670}
    751671
    752 //++
    753 // Titre        Opérations
    754 //--
    755 
    756 //++
     672//! Operator: return P(x) = *this(x) + b(x)
    757673Poly2& Poly2::operator += (Poly2 const& b)
    758 //
    759 //--
    760674{
    761675  if (maxDegX < b.DegX() || maxDegY < b.DegY())
     
    774688}
    775689
    776 //++
     690//! Operator: return P(x) = *this(x) - b(x)
    777691Poly2& Poly2::operator -= (Poly2 const& b)
    778 //
    779 //--
    780692{
    781693  if (maxDegX < b.DegX() || maxDegY < b.DegY())
     
    794706}
    795707
    796 //++
     708//! Operator: return P(x) = *this(x) * a
    797709Poly2& Poly2::operator *= (double a)
    798 //
    799 //--
    800710{
    801711  for (int i=0; i<NElts(); i++)
     
    805715}
    806716
    807 //++
     717//! Operator: return P(x) = *this(x) * b(x)
    808718Poly2 Poly2::Mult(Poly2 const& b) const
    809 //
    810 //--
    811719{
    812720  Poly2 c(DegX() + b.DegX(), DegY() + b.DegY());
     
    822730}
    823731
    824 //++
     732//! Return \f$ P(x,y)^n \f$
    825733Poly2 Poly2::power(int n) const
    826 //
    827 //      Calcule le polynôme P(x,y)^n
    828 //--
    829734{
    830735  if (n < 0) THROW(rangeCheckErr);
     
    835740
    836741
    837 //++
     742//! substitute and return \f$ P(a(x),b(x)) \f$
    838743Poly2 Poly2::operator() (Poly const& a, Poly const& b) const
    839 //
    840 //      Substitution de deux polynômes en X et Y,
    841 //      P2(pa(x), pb(y)).
    842 //--
    843744{
    844745  UpdateDegIfDirty();
     
    854755}
    855756
    856 //++
     757//! substitute and return 2D polynomial \f$ P(a(x,y)) \f$, P is a 1D polynomial
    857758Poly2 Poly::operator() (Poly2 const& a) const
    858 //
    859 //      Substitution d'un polynôme à deux variables dans
    860 //      un polynôme à une variable, P(P2(x,y)).
    861 //--
    862759{
    863760  Poly2 c(a.MaxDegX()*Degre(), a.MaxDegY()*Degre());
     
    869766
    870767//////////////////////////////////////////////////////////////////////////
     768//! For persistance management
    871769void ObjFileIO<Poly2>::ReadSelf(PInPersist& is)
    872770{
     
    879777}
    880778
     779//! For persistance management
    881780void ObjFileIO<Poly2>::WriteSelf(POutPersist& os) const
    882781{
Note: See TracChangeset for help on using the changeset viewer.