Allink
v0.1
|
00001 #ifndef MATEMATICA_H 00002 #define MATEMATICA_H 00003 #include <stdio.h> 00004 #include <stdlib.h> 00005 #include <string.h> 00006 #include <math.h> 00007 #include <stdarg.h> 00008 #include <fstream> 00009 #include <iostream> 00010 //#include <time.h> 00011 //#include <complex> 00012 //to look up! 00013 //#include <boost/math/special_functions/fpclassify.hpp> 00014 #include <assert.h> 00015 #ifndef __GSL__ 00016 #include "randomlib.h" 00017 #include "MatematicaVect.h" 00018 #include "MatematicaQuadri.h" 00019 #include "MatematicaMatrix.h" 00020 #include "MatematicaStruct.h" 00021 #include "MatematicaPlane.h" 00022 #include <mt19937ar.h> 00023 #else 00024 #include <gsl/gsl_math.h> 00025 #include <gsl/gsl_rng.h> 00026 #endif 00027 #ifndef FFTW3_H 00028 #include <fftw3.h> 00029 #endif 00030 #define STRSIZE 512 00031 #define STRLEN STRSIZE 00032 #define QUAD(A) ((A)*(A)) 00033 #define SQUARE(A) QUAD(A) 00034 #define SQR(A) QUAD(A) 00035 #define CUB(A) (QUAD(A)*(A)) 00036 #define CUBE(A) (QUAD(A)*(A)) 00037 #define SIGN(A) (A>0?1.:-1.) 00038 #define NTAB 32 00039 #define DUE_PI (6.2831853071795864769252867665590057683943) 00040 #define DEG_RAD (0.0174532925199433) 00041 #define RAD_DEG (57.2957795130823) 00042 #define INV_DUE_PI (0.159154943091895) 00043 #define PI M_PI 00044 #define SQRT_PI 1.77245385090552 00045 #define MIN(a,b) ( ( (a)<=(b) ) ? (a) : (b) ) 00046 #define MIN3(a,b,c) ( MIN(MIN(a,b),c) ) 00047 #define MAS(a,b) ( ( (a)>=(b) ) ? (a):(b) ) 00048 #define MAX(a,b) MAS(a,b) 00049 #define POS(a) ( ( a>=0 ) ? (a):(-a) ) 00050 #define ASS(a) POS(a) 00051 #define ABS(a) POS(a) 00052 #define OP_IF(c,t) ( ((c)&(t))==(t) ) 00053 #define OP_INVERT 0x00001 00054 #define OP_ROT_90 0x00002 00055 #define OP_ROT_180 0x00004 00056 #define OP_MIRROR 0x00008 00057 #define OP_ROT_270 0x0000c 00058 #define OP_TRANSPOSE 0x0000f 00059 00060 using namespace std; 00061 00062 //---------------------Miscellaneous------------------ 00063 int NumeroStringa(const char *NumeroC); 00064 void abort_(const char * s, ...); 00065 void SigErr(int IfWrong,const char * s, ...); 00066 void Message(const char * s, ...); 00067 double rnor(); 00068 //float nfix(void); 00069 //float efix(void); 00070 float zigset(unsigned long); 00071 /* double Evalx(void (*pt2Function)(double x)){ */ 00072 /* return pt2Function(.2); */ 00073 /* } */ 00074 //-------------------Matematica------------------------ 00076 class Matematica{ 00077 private: 00079 SPLINE SpMem; 00081 double PrecMinimo; 00083 int NPassi; 00084 #ifdef __GSL__ 00085 gsl_rng *rng; 00086 #endif 00087 public: 00089 Matematica(); 00091 ~Matematica(); 00092 //-----------------------Filter---------------------------- 00094 int PermuteRandomAll(int *Sequence,int NMass); 00096 int PermuteRandomAll(PERMUTE *Sequence,int NMass); 00098 int ApplyFilter(Matrice *Point,Matrice *Res,Matrice *Mask); 00100 int ApplyFilter(Matrice *Res,Matrice *Mask); 00102 int Transform(int *Out,int *In,int NEdge,int operation); 00104 void BackFold(Matrice *In,Matrice *Out,int NShift); 00106 void Smooth(double *st,double *sw,int NIn,int NOut); 00107 //------------------------Func------------------------ 00109 typedef double(Matematica::*FUNC)(double x); 00111 FUNC Func; 00113 double Evalx(double x){return (*this.*Func)(x);} 00115 double ContactAngle(double x); 00117 double fProva(double x); 00118 /* /// Boh */ 00119 /* double *fp; */ 00121 double F(double TD,double T); 00123 double Df(double x,double Delta); 00124 //template <class Elabora> Elabora ElabFunc(double *st,double *sw,int NMass); 00125 //template <class Elabora> Elabora Elaboro(double *st,double *sw,int NMass){return (*this.*ElabFunc)(st,sw,NMass);}; 00126 // NPunti = Elabora<int>(st,sw,NMass); 00127 typedef void(Matematica::*ELAB)(double *st,double *sw,int NMass); 00128 ELAB Elab; 00130 void ElabSt(double *st,double *sw,int NMass){return (*this.*Elab)(st,sw,NMass);}; 00132 void Derivata(double *st,double *sw,int NMass); 00134 void DerO4(double *st,double *sw,int NMass); 00136 double Integrazione(double *Punti,double *sw,int NMass); 00138 void IntegraA3(); 00140 void SquareGradient(double *st,double *sw,int NMass); 00142 double Integrazione(double a,double b); 00144 double IntegrazioneGauss(double a,double b,double Scarto); 00146 int Zeri(double a,double b,double *Radici,int NRadici); 00148 RADICE RegulaFalsi(double a,double b); 00150 RADICE Newton(double a); 00152 double Estremo(double a,double b); 00154 double Fattoriale(int n); 00156 double Gamma(int n); 00158 double Elevato(double x,int Volte); 00160 double Bessel(double Val,int Ord); 00162 double Neumann(double Val,int Ord); 00164 double Segno(int n); 00166 double QuasiBessel(double Val,int Ord); 00168 double QuasiNeumann(double Val,int Ord); 00170 double WeightFunction(double x,double a); 00172 double WeightFunction2(double x,double a); 00174 double LJHamaker(double r,double r_np,double theta); 00176 double LJHamakerCum(double Rad,double RadNpMin,double RadNpMax); 00178 double LJHamaker(double Rad,double r_np); 00180 double LJ39(double r,double r_np); 00181 //-----------------------Sign--------------------- 00183 void ExecCommand(double *st,double *st1,int NMass,char *cmd); 00185 double ExecFormula(double x,double y,char *cmd); 00187 double ExecFormula(double **st,int n,char *cmd); 00189 double Gauss(double Media,double Scarto,double x); 00191 bool InizializzaGaussiano(double Scarto,int N); 00193 double Gaussiano(double Media,double Scarto); 00195 void Spettro(double *st,double *sw,int NMass); 00197 void Spettro2d(double *st,double *sw,int NMass); 00199 void Spettro2d(double *st,double **sw,int NMass); 00201 void SpettroDFT(double *st,double *sw,int NMass); 00203 void Radice(double *st,double *sw,int N); 00205 void Autocor(bool *st,double *sAuto,int N); 00207 void Autocor(double *st,double *sAuto,int NMass); 00209 double Norm(double *st,int NMass); 00211 int NormalizeArea(double *st,int NMass); 00213 void NormalizeVect(double *st,int NMass); 00215 int Normalizza(double *st,int NMass); 00217 int Normalizza(double *st,double *sw,int NMass); 00219 void Modulo(double *st,double *sw,int NMass); 00221 void MediaMobile(double *st,int NMass,double *sw,int Parti); 00223 int MediaMobile(double *st,int NMass,double *sw,double *sErr,int Parti); 00225 int CorrelaDuePunti(double *st,int NMass,double *sw,int Punti); 00227 void Autosimilarita(double *st,int NMass,double *sw,int Valori); 00229 MOMENTI Distribuzione(const double *st,int NMass); 00231 MOMENTI Distribuzione(const double *st,int NMass,double *Intervalli,int Valori,int IfNorm); 00233 MOMENTI Distribuzione(const double *st,int NMass,double *Intervalli,int Valori,double *Confine,int IfNorm); 00235 MOMENTI DistrErr(const double *st,int NMass,double *Intervalli,double *Err,int Valori,double *Confine,int IfNorm); 00237 MOMENTI DistribuzioneGauss(const double *st,int NMass,double *Intervalli,double *dInt,int Valori,int IfNorm); 00239 MOMENTI DistribuzioneMaxwell(const double *st,int NMass,double *Intervalli,double *dInt,int Valori,int IfNorm); 00241 void DistrSample(double *Px,double *Py,int NMax,double **Distr,int NBin,const int NSample,int IfNorm,double *xBound); 00243 MOMENTI WeightAverage(const double *sx,const double *sy,int NMax); 00245 void WeightHisto(double **hist,double *Border,int NBin,int NHisto,double tolerance,double *OrPos,double *kSpring); 00247 void Sort(double *Sign,int NMass); 00249 void Swap(int i,int j,double *Sign); 00251 void Swap(double *s,int si,double *t,int ti,const int NDim); 00253 void Sort(int *Sign,int NMass); 00255 void Swap(int i,int j,int *Sign); 00257 void FileSin1d(char *FName); 00259 void FileSin2d(char *FName); 00261 void ConvWeight(double *st,int NMax,double *sw,int *WIndex,int NWeight); 00263 void FillWeightGauss(double *st,int *WIndex,int NWeight,double CutOff,double Sigma); 00264 //--------------------Interp-------------------------------- 00266 double LinInterp(double Px1,double Px2,double Py1,double Py2,double x); 00268 RETTA InterRett(double *Px,double *Py,int NMass); 00270 RETTA InterExp(double *Px,double *Py,int NMass); 00272 MOMENTI InterGauss(double *Px,double *Py,int NMass); 00274 RETTA InterRett(double *Px,double *Py,double *Peso,int NMass); 00276 PARABOLA MinimoParabola(double a, double b,double *Px,double *Py,int NMass); 00278 PARABOLA MinimoParabola(double *Px,double *Py,int NMass); 00280 SPLINE Parab(double *P1,double *P2,double *P3,int x,int y); 00282 SPLINE Parab2(double *PA,double *PB,double *PC,int x,int y); 00284 CIRCLE Osculante(double *PA,double *PB,double *PC,int x,int y); 00286 SPLINE Cubica(double *PA,double *PB,double *PC,double *PD,int x,int y); 00288 SPLINE Forth(double *PA,double *PB,double *PC,double *PD,double *PE,int x,int y); 00290 SPLINE Spline3(double *P1,double *P2,double *P3,int x,int y); 00292 SPLINE Spline3Beg(double *P1,double *P2,double *P3,int x,int y); 00294 SPLINE Spline3End(double *P1,double *P2,int x,int y); 00296 SPLINE Spline4Beg(double *P1,double *P2,double *P3,double *P4,int x,int y); 00298 SPLINE Spline4(double *P1,double *P2,double *P3,double *P4,int x,int y); 00300 SPLINE Spline4(double *P1,double *P2,double *P3,int x,int y); 00302 SPLINE Spline4PreEnd(double *P1,double *P2,double *P3,int x,int y); 00304 SPLINE Spline4End(double *P1,double *P2,int x,int y); 00306 int Polinomio(double *P1,double *P2,int NMass,Spline *Sp); 00308 int DerMatrix(double *Px,double *Py,int NMass,SPLINE Wg,Spline *Sp); 00310 double Casuale(); 00312 double RandDiscrProb(double *Prob,int NBin); 00314 double QBezier(double *P1,double *P2,double *P3,double x,int y); 00316 int Factorial(int times); 00318 double Binomial(int times,int n); 00320 double Blend(const double *dPoint,double x,int nPoint,int nOrder); 00322 double Blend(double *dPoint,size_t Incr,double x,int nPoint,int nOrder); 00324 int InterBSpline2D(Matrice *MaIn,Matrice *MaOut); 00326 int Voronoi(); 00327 //---------------------------Algebra------------------------------ 00328 // int Invert(Matrice A,Matrice B); 00330 double Ypsilon; 00332 double PreFact; 00333 }; 00334 //-----------------------Char--------------------- 00336 uint sTable(char *String); 00338 uint sTable(char Char); 00339 //--------------------Trials--------------------- 00340 class Funtore{ 00341 public: 00342 virtual double operator()(double x)=0; 00343 virtual double Call(double x)=0; 00344 }; 00345 template <class Classe> class SpecFuntore : public Funtore{ 00346 private: 00347 double (Classe::*ftp)(const double x); 00348 Classe* pt2Object; 00349 public: 00350 SpecFuntore(Classe* _pt2Object,void (Classe::*_ftp)(double x)) 00351 { pt2Object = _pt2Object; ftp = _ftp; }; 00352 virtual double operator()(const double x) 00353 { return (*pt2Object.*ftp)(x);}; 00354 virtual double Call(double x) 00355 { return (*pt2Object.*ftp)(x);}; 00356 }; 00357 00358 #endif //MATEMATICA_H