Allink  v0.1
Matematica.h
1 #ifndef MATEMATICA_H
2 #define MATEMATICA_H
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <math.h>
7 #include <stdarg.h>
8 #include <fstream>
9 #include <iostream>
10 //#include <time.h>
11 //#include <complex>
12 //to look up!
13 //#include <boost/math/special_functions/fpclassify.hpp>
14 #include <assert.h>
15 #include "randomlib.h"
16 #include "MatematicaVect.h"
17 #include "MatematicaQuadri.h"
18 #include "MatematicaMatrix.h"
19 #include "MatematicaStruct.h"
20 #include "MatematicaPlane.h"
21 #include <mt19937ar.h>
22 #ifndef __GSL__
23 #else
24 #include <gsl/gsl_math.h>
25 #include <gsl/gsl_rng.h>
26 #endif
27 #ifndef FFTW3_H
28 #include <fftw3.h>
29 #endif
30 #define STRSIZE 512
31 #define STRLEN STRSIZE
32 #define QUAD(A) ((A)*(A))
33 #define SQUARE(A) QUAD(A)
34 #define SQR(A) QUAD(A)
35 #define CUB(A) (QUAD(A)*(A))
36 #define CUBE(A) (QUAD(A)*(A))
37 #define SIGN(A) (A>0?1.:-1.)
38 #define NTAB 32
39 #define DUE_PI (6.2831853071795864769252867665590057683943)
40 #define DEG_RAD (0.0174532925199433)
41 #define RAD_DEG (57.2957795130823)
42 #define INV_DUE_PI (0.159154943091895)
43 #define PI M_PI
44 #define SQRT_PI 1.77245385090552
45 #define MIN(a,b) ( ( (a)<=(b) ) ? (a) : (b) )
46 #define MIN3(a,b,c) ( MIN(MIN(a,b),c) )
47 #define MAS(a,b) ( ( (a)>=(b) ) ? (a):(b) )
48 #define MAX(a,b) MAS(a,b)
49 #define POS(a) ( ( a>=0 ) ? (a):(-a) )
50 #define ASS(a) POS(a)
51 #define ABS(a) POS(a)
52 #define OP_IF(c,t) ( ((c)&(t))==(t) )
53 #define OP_INVERT 0x00001
54 #define OP_ROT_90 0x00002
55 #define OP_ROT_180 0x00004
56 #define OP_MIRROR 0x00008
57 #define OP_ROT_270 0x0000c
58 #define OP_TRANSPOSE 0x0000f
59 
60 using namespace std;
61 
62 //---------------------Miscellaneous------------------
63 int NumeroStringa(const char *NumeroC);
64 void abort_(const char * s, ...);
65 void SigErr(int IfWrong,const char * s, ...);
66 void Message(const char * s, ...);
67 double rnor();
68 //float nfix(void);
69 //float efix(void);
70 float zigset(unsigned long);
71 /* double Evalx(void (*pt2Function)(double x)){ */
72 /* return pt2Function(.2); */
73 /* } */
74 //-------------------Matematica------------------------
76 class Matematica{
77  private:
79  SPLINE SpMem;
81  double PrecMinimo;
83  int NPassi;
84 #ifdef __GSL__
85  gsl_rng *rng;
86 #endif
87  public:
89  Matematica();
91  ~Matematica();
92  //-----------------------Filter----------------------------
94  int PermuteRandomAll(int *Sequence,int NMass);
96  int PermuteRandomAll(PERMUTE *Sequence,int NMass);
98  int ApplyFilter(Matrice *Point,Matrice *Res,Matrice *Mask);
100  int ApplyFilter(Matrice *Res,Matrice *Mask);
102  int Transform(int *Out,int *In,int NEdge,int operation);
104  void BackFold(Matrice *In,Matrice *Out,int NShift);
106  void Smooth(double *st,double *sw,int NIn,int NOut);
107  //------------------------Func------------------------
109  typedef double(Matematica::*FUNC)(double x);
111  FUNC Func;
113  double Evalx(double x){return (*this.*Func)(x);}
115  double ContactAngle(double x);
117  double fProva(double x);
118  /* /// Boh */
119  /* double *fp; */
121  double F(double TD,double T);
123  double Df(double x,double Delta);
124  //template <class Elabora> Elabora ElabFunc(double *st,double *sw,int NMass);
125  //template <class Elabora> Elabora Elaboro(double *st,double *sw,int NMass){return (*this.*ElabFunc)(st,sw,NMass);};
126  // NPunti = Elabora<int>(st,sw,NMass);
127  typedef void(Matematica::*ELAB)(double *st,double *sw,int NMass);
128  ELAB Elab;
130  void ElabSt(double *st,double *sw,int NMass){return (*this.*Elab)(st,sw,NMass);};
132  void Derivata(double *st,double *sw,int NMass);
134  void DerO4(double *st,double *sw,int NMass);
136  double Integrazione(double *Punti,double *sw,int NMass);
138  void IntegraA3();
140  void SquareGradient(double *st,double *sw,int NMass);
142  double Integrazione(double a,double b);
144  double IntegrazioneGauss(double a,double b,double Scarto);
146  int Zeri(double a,double b,double *Radici,int NRadici);
148  RADICE RegulaFalsi(double a,double b);
150  RADICE Newton(double a);
152  double Estremo(double a,double b);
154  double Fattoriale(int n);
156  double Gamma(int n);
158  double Elevato(double x,int Volte);
160  double Bessel(double Val,int Ord);
162  double Neumann(double Val,int Ord);
164  double Segno(int n);
166  double QuasiBessel(double Val,int Ord);
168  double QuasiNeumann(double Val,int Ord);
170  double WeightFunction(double x,double a);
172  double WeightFunction2(double x,double a);
174  double LJHamaker(double r,double r_np,double theta);
176  double LJHamakerCum(double Rad,double RadNpMin,double RadNpMax);
178  double LJHamaker(double Rad,double r_np);
180  double LJ39(double r,double r_np);
181  //-----------------------Sign---------------------
183  void ExecCommand(double *st,double *st1,int NMass,char *cmd);
185  double ExecFormula(double x,double y,char *cmd);
187  double ExecFormula(double **st,int n,char *cmd);
189  double Gauss(double Media,double Scarto,double x);
191  bool InizializzaGaussiano(double Scarto,int N);
193  double Gaussiano(double Media,double Scarto);
195  void Spettro(double *st,double *sw,int NMass);
197  void Spettro2d(double *st,double *sw,int NMass);
199  void Spettro2d(double *st,double **sw,int NMass);
201  void SpettroDFT(double *st,double *sw,int NMass);
203  void Radice(double *st,double *sw,int N);
205  void Autocor(bool *st,double *sAuto,int N);
207  void Autocor(double *st,double *sAuto,int NMass);
209  double Norm(double *st,int NMass);
211  int NormalizeArea(double *st,int NMass);
213  void NormalizeVect(double *st,int NMass);
215  int Normalizza(double *st,int NMass);
217  int Normalizza(double *st,double *sw,int NMass);
219  void Modulo(double *st,double *sw,int NMass);
221  void MediaMobile(double *st,int NMass,double *sw,int Parti);
223  int MediaMobile(double *st,int NMass,double *sw,double *sErr,int Parti);
225  int CorrelaDuePunti(double *st,int NMass,double *sw,int Punti);
227  void Autosimilarita(double *st,int NMass,double *sw,int Valori);
229  MOMENTI Distribuzione(const double *st,int NMass);
231  MOMENTI Distribuzione(const double *st,int NMass,double *Intervalli,int Valori,int IfNorm);
233  MOMENTI Distribuzione(const double *st,int NMass,double *Intervalli,int Valori,double *Confine,int IfNorm);
235  MOMENTI DistrErr(const double *st,int NMass,double *Intervalli,double *Err,int Valori,double *Confine,int IfNorm);
237  MOMENTI DistribuzioneGauss(const double *st,int NMass,double *Intervalli,double *dInt,int Valori,int IfNorm);
239  MOMENTI DistribuzioneMaxwell(const double *st,int NMass,double *Intervalli,double *dInt,int Valori,int IfNorm);
241  void DistrSample(double *Px,double *Py,int NMax,double **Distr,int NBin,const int NSample,int IfNorm,double *xBound);
243  MOMENTI WeightAverage(const double *sx,const double *sy,int NMax);
245  void WeightHisto(double **hist,double *Border,int NBin,int NHisto,double tolerance,double *OrPos,double *kSpring);
247  void Sort(double *Sign,int NMass);
249  void Swap(int i,int j,double *Sign);
251  void Swap(double *s,int si,double *t,int ti,const int NDim);
253  void Sort(int *Sign,int NMass);
255  void Swap(int i,int j,int *Sign);
257  void FileSin1d(char *FName);
259  void FileSin2d(char *FName);
261  void ConvWeight(double *st,int NMax,double *sw,int *WIndex,int NWeight);
263  void FillWeightGauss(double *st,int *WIndex,int NWeight,double CutOff,double Sigma);
264  //--------------------Interp--------------------------------
266  double LinInterp(double Px1,double Px2,double Py1,double Py2,double x);
268  RETTA InterRett(double *Px,double *Py,int NMass);
270  RETTA InterExp(double *Px,double *Py,int NMass);
272  MOMENTI InterGauss(double *Px,double *Py,int NMass);
274  RETTA InterRett(double *Px,double *Py,double *Peso,int NMass);
276  PARABOLA MinimoParabola(double a, double b,double *Px,double *Py,int NMass);
278  PARABOLA MinimoParabola(double *Px,double *Py,int NMass);
280  SPLINE Parab(double *P1,double *P2,double *P3,int x,int y);
282  SPLINE Parab2(double *PA,double *PB,double *PC,int x,int y);
284  CIRCLE Osculante(double *PA,double *PB,double *PC,int x,int y);
286  SPLINE Cubica(double *PA,double *PB,double *PC,double *PD,int x,int y);
288  SPLINE Forth(double *PA,double *PB,double *PC,double *PD,double *PE,int x,int y);
290  SPLINE Spline3(double *P1,double *P2,double *P3,int x,int y);
292  SPLINE Spline3Beg(double *P1,double *P2,double *P3,int x,int y);
294  SPLINE Spline3End(double *P1,double *P2,int x,int y);
296  SPLINE Spline4Beg(double *P1,double *P2,double *P3,double *P4,int x,int y);
298  SPLINE Spline4(double *P1,double *P2,double *P3,double *P4,int x,int y);
300  SPLINE Spline4(double *P1,double *P2,double *P3,int x,int y);
302  SPLINE Spline4PreEnd(double *P1,double *P2,double *P3,int x,int y);
304  SPLINE Spline4End(double *P1,double *P2,int x,int y);
306  int Polinomio(double *P1,double *P2,int NMass,Spline *Sp);
308  int DerMatrix(double *Px,double *Py,int NMass,SPLINE Wg,Spline *Sp);
310  double Casuale();
312  double RandDiscrProb(double *Prob,int NBin);
314  double QBezier(double *P1,double *P2,double *P3,double x,int y);
316  int Factorial(int times);
318  double Binomial(int times,int n);
320  double Blend(const double *dPoint,double x,int nPoint,int nOrder);
322  double Blend(double *dPoint,size_t Incr,double x,int nPoint,int nOrder);
324  int InterBSpline2D(Matrice *MaIn,Matrice *MaOut);
326  int Voronoi();
327  //---------------------------Algebra------------------------------
328  // int Invert(Matrice A,Matrice B);
330  double Ypsilon;
332  double PreFact;
333 };
334 //-----------------------Char---------------------
336 uint sTable(char *String);
338 uint sTable(char Char);
339 //--------------------Trials---------------------
340 class Funtore{
341  public:
342  virtual double operator()(double x)=0;
343  virtual double Call(double x)=0;
344 };
345 template <class Classe> class SpecFuntore : public Funtore{
346  private:
347  double (Classe::*ftp)(const double x);
348  Classe* pt2Object;
349  public:
350  SpecFuntore(Classe* _pt2Object,void (Classe::*_ftp)(double x))
351  { pt2Object = _pt2Object; ftp = _ftp; };
352  virtual double operator()(const double x)
353  { return (*pt2Object.*ftp)(x);};
354  virtual double Call(double x)
355  { return (*pt2Object.*ftp)(x);};
356 };
357 
358 #endif //MATEMATICA_H
double Ypsilon
External parameter to calculate the contact angle.
Definition: Matematica.h:330
coeficients of a N order spline
Parabolas coefficients.
STL namespace.
Indices for the permutation.
void ElabSt(double *st, double *sw, int NMass)
Pointer to a function which operates on.
Definition: Matematica.h:130
FUNC Func
Pointer to a function.
Definition: Matematica.h:111
Linear interpolation.
Moments of a distribution.
double PreFact
External parameter in the definition of the contact angle.
Definition: Matematica.h:332
Matrice computes the algebric operations on matrices.
Where a root was searched.
double Evalx(double x)
Pointer to a generic function.
Definition: Matematica.h:113
Implementation of useful algorythms.
Definition: Matematica.h:76
Radius and center of a circle.
Coefficient of a spline.