Changeset 514 in Sophya for trunk/SophyaLib/NTools/poly.h
- Timestamp:
- Oct 25, 1999, 6:43:04 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/NTools/poly.h
r508 r514 1 1 // This may look like C code, but it is really -*- C++ -*- 2 2 // 3 // $Id: poly.h,v 1. 2 1999-10-25 10:36:11 ansari Exp $3 // $Id: poly.h,v 1.3 1999-10-25 16:40:01 ansari Exp $ 4 4 // 5 6 5 7 6 // Des polynomes avec des operations de bases et surtout des fits. … … 10 9 #define POLY_SEEN 11 10 11 #include "objfio.h" 12 12 #include <stdio.h> 13 13 #include "peida.h" 14 #include "cvector.h" 14 #include "tvector.h" 15 #include "ppersist.h" 16 #include "anydataobj.h" 17 18 namespace PlanckDPC { 15 19 16 20 class Poly2; 17 21 18 class Poly : public OVector { 22 ////////////////////////////////////////////////////////////////////////// 23 class Poly : public Vector { 24 friend class ObjFileIO<Poly>; 19 25 public: 20 26 Poly(int degre = 0); 27 Poly(Poly const& a); 21 28 22 29 enum {classId = ClassId_Poly1}; 23 int_4 ClassId() const { return classId; } 24 static PPersist* Create() {return new Poly;} 30 int_4 ClassId() const { return classId; } 25 31 26 32 inline int Degre() const {UpdateDegIfDirty(); return deg;} 27 33 28 inline void Realloc(int n, bool force=false) { OVector::Realloc(n+1,force);}29 30 inline double operator[](int i) const {return data[i];}31 inline double& operator[](int i) {dirty = 1; return data[i];}34 inline void Realloc(int n, bool force=false) {Vector::Realloc(n+1,force);} 35 36 inline double operator[](int i) const {return Element(i);} 37 inline double& operator[](int i) {dirty = 1; return Element(i);} 32 38 // Retourne le coefficient de degre i 33 39 … … 41 47 // Derive le polynome dans un autre 42 48 43 int Roots( OVector& roots) const;49 int Roots(Vector& roots) const; 44 50 // retourne les racines si on peut les calculer... 45 51 … … 49 55 int Root2(double& r1, double& r2) const; 50 56 // special degre 2 51 52 friend Poly operator* (Poly const& a, Poly const& b);53 friend Poly operator+ (Poly const& a, Poly const& b);54 friend Poly operator- (Poly const& a, Poly const& b);55 57 56 58 Poly& operator = (Poly const& b); … … 58 60 Poly& operator -= (Poly const& b); 59 61 60 friend Poly operator* (double a, Poly const& b);61 62 62 Poly& operator *= (double a); 63 64 Poly Mult(Poly const& b) const; 63 65 64 66 Poly power(int n) const; … … 66 68 Poly2 operator() (Poly2 const& b) const; 67 69 68 void ReadSelf(PInPersist&);69 void WriteSelf(POutPersist&) const;70 71 70 void Print(ostream& s) const; 72 friend ostream& operator << (ostream& s, const Poly& a); 73 74 double Fit(OVector const& x, OVector const& y, int degre); 71 72 double Fit(Vector const& x, Vector const& y, int degre); 75 73 // Fit d'un polynome de degre donne sur les x et y. 76 74 77 double Fit( OVector const& x, OVector const& y, OVector const& erry2, int degre,78 OVector& errCoef);75 double Fit(Vector const& x, Vector const& y, Vector const& erry2, int degre, 76 Vector& errCoef); 79 77 // En plus, on fournit les carres des erreurs sur y et on a les erreurs 80 78 // sur les coefficients dans un vecteur. … … 87 85 }; 88 86 87 inline Poly operator* (Poly const& a, Poly const& b) 88 { return a.Mult(b); } 89 90 inline Poly operator+ (Poly const& a, Poly const& b) 91 { Poly c((a.Degre() > b.Degre())?(a.Degre()+1):(b.Degre()+1)); 92 c = a; c += b; return c; } 93 94 inline Poly operator- (Poly const& a, Poly const& b) 95 { Poly c((a.Degre() > b.Degre())?(a.Degre()+1):(b.Degre()+1)); 96 c = a; c -= b; return c; } 97 98 inline Poly operator* (double a, Poly const& b) 99 { Poly c(b); c *= a; return c; } 100 101 inline ostream& operator << (ostream& s, const Poly& a) 102 { a.Print(s); return s; } 103 104 ////////////////////////////////////////////////////////////////////////// 105 inline POutPersist& operator << (POutPersist& os, Poly & obj) 106 { ObjFileIO<Poly> fio(&obj); fio.Write(os); return(os); } 107 inline PInPersist& operator >> (PInPersist& is, Poly & obj) 108 { ObjFileIO<Poly> fio(&obj); fio.Read(is); return(is); } 109 // Classe pour la gestion de persistance 110 // ObjFileIO<Poly> 111 112 ////////////////////////////////////////////////////////////////////////// 89 113 int binomial(int n, int p); 90 114 91 92 class Poly2 : public OVector { // Ca pourrait etre une matrice mais 93 // la encore, un vecteur est utile pour les 94 // fits. 95 115 ////////////////////////////////////////////////////////////////////////// 116 class Poly2 : public Vector { 117 friend class ObjFileIO<Poly2>; 96 118 public: 97 119 Poly2(int degreX=0, int degreY=0); … … 101 123 102 124 enum {classId = ClassId_Poly2}; 103 int_4 ClassId() const { return classId; } 104 static PPersist* Create() {return new Poly2;} 125 int_4 ClassId() const { return classId; } 105 126 106 127 inline int DegX() const {UpdateDegIfDirty(); return degX;} … … 123 144 124 145 inline double Coef(int dx, int dy) const { 125 return (dx>maxDegX || dy>maxDegY) ? 0 : data[IndCoef(dx,dy)];146 return (dx>maxDegX || dy>maxDegY) ? 0 : Element(IndCoef(dx,dy)); 126 147 } 127 148 inline double& Coef(int dx, int dy) { 128 149 if (dx>maxDegX || dy>maxDegY) THROW(rangeCheckErr); 129 dirty = 1; return data[IndCoef(dx,dy)];150 dirty = 1; return Element(IndCoef(dx,dy)); 130 151 } 131 152 // retourne le coefficient de degre (dx,dy) 132 153 133 double Fit( OVector const& x, OVector const& y, OVector const& z,154 double Fit(Vector const& x, Vector const& y, Vector const& z, 134 155 int degreX, int degreY); 135 double Fit( OVector const& x, OVector const& y, OVector const& z,136 OVector const& errz2, int degreX, int degreY,137 OVector& errCoef);156 double Fit(Vector const& x, Vector const& y, Vector const& z, 157 Vector const& errz2, int degreX, int degreY, 158 Vector& errCoef); 138 159 // degres partiels imposes. cf Poly::Fit sinon 139 160 140 161 141 double Fit( OVector const& x, OVector const& y, OVector const& z,162 double Fit(Vector const& x, Vector const& y, Vector const& z, 142 163 int degre); 143 double Fit( OVector const& x, OVector const& y, OVector const& z,144 OVector const& errz2, int degre,145 OVector& errCoef);164 double Fit(Vector const& x, Vector const& y, Vector const& z, 165 Vector const& errz2, int degre, 166 Vector& errCoef); 146 167 // degre total impose. cf Poly::Fit sinon 147 168 … … 151 172 Poly2& operator -= (Poly2 const& b); 152 173 153 friend Poly2 operator + (Poly2 const& a, Poly2 const& b);154 friend Poly2 operator - (Poly2 const& a, Poly2 const& b); 155 friend Poly2 operator * (Poly2 const& a, Poly2 const& b);174 Poly2& operator *= (double a); 175 176 Poly2 Mult(Poly2 const& b) const; 156 177 157 178 Poly2 power(int n) const; 158 159 Poly2& operator *= (double a);160 friend Poly2 operator * (double a, Poly2 const& b);161 179 162 180 Poly2 operator() (Poly const& px, Poly const& py) const; … … 165 183 void Realloc(int degreX, int degreY); 166 184 167 void ReadSelf(PInPersist&);168 void WriteSelf(POutPersist&) const;169 170 185 void Print(ostream& s) const; 171 friend ostream& operator << (ostream& s, const Poly2& a);172 186 173 187 private: … … 182 196 }; 183 197 198 inline Poly2 operator* (Poly2 const& a, Poly2 const& b) 199 { return a.Mult(b); } 200 201 inline Poly2 operator+ (Poly2 const& a, Poly2 const& b) 202 { Poly2 c(a); c += b; return c; } 203 204 inline Poly2 operator- (Poly2 const& a, Poly2 const& b) 205 { Poly2 c(a); c -= b; return c; } 206 207 inline Poly2 operator * (double a, Poly2 const& b) 208 { Poly2 c(b); c *= a; return c; } 209 210 inline ostream& operator << (ostream& s, const Poly2& a) 211 { a.Print(s); return s; } 212 213 ////////////////////////////////////////////////////////////////////////// 214 inline POutPersist& operator << (POutPersist& os, Poly2 & obj) 215 { ObjFileIO<Poly2> fio(&obj); fio.Write(os); return(os); } 216 inline PInPersist& operator >> (PInPersist& is, Poly2 & obj) 217 { ObjFileIO<Poly2> fio(&obj); fio.Read(is); return(is); } 218 // Classe pour la gestion de persistance 219 // ObjFileIO<Poly2> 220 221 222 } // Fin du namespace 223 184 224 #endif // POLY_SEEN
Note:
See TracChangeset
for help on using the changeset viewer.