1 #include "../include/Matematica.h" 15 Ris = 1./(13.9332529115775*x*x - 4.*13.9332529115775*0.13710248135043*x + 7.86306085419497) + .5/(-0.0805855688278211*x + 10.6925178203198);
23 double Delta = (b-a)/(
double)NPassi;
25 for(
int i=0;a+((double)i)*Delta<b;i+=3){
26 Risp += 3.*3.*Delta*(
Evalx(a+Delta*i)+3.*
Evalx(a+Delta*(i+1))+3.*
Evalx(a+Delta*(i+2))+
Evalx(a+Delta*(i+3)) )/8.;
31 double NMassInv = 1/((double)NMass);
33 for(
int i=1;i<NMass;i++){
34 sw[i] = st[i] + sw[i-1];
42 for(
int i=0;i<NMass-1;i++){
43 sw[i] = (st[i+1]-st[i])/2.;
49 for(
int i=1;i<NMass-1;i++){
51 sw[i] = (st[i+1] - st[i-1])/2.;
52 else if (i < NMass - 2)
53 sw[i] = st[i-2] - 8.*st[i-1] + 8.*st[i+1] - st[i+2];
54 else if (i < NMass - 1)
55 sw[i] = (st[i+1] - st[i-1])/2.;
59 double Uno;
double Due;
double Delta;
68 Delta = (Due - Uno)/2.;
70 for(
int i=0;i<NRadici*2;i++){
71 Delta = (Due - Uno)/(2*NRadici);
72 Rad =
RegulaFalsi(Uno+i*Delta,Due-(2*NRadici-i-1)*Delta);
75 printf(
"Found a root in %lf\n",Rad.
Zero);
76 Radici[rad] = Rad.
Zero;
84 double Uno;
double Due;
double Tre;
88 Delta=(b-a)/(
double)NLim;
90 for(
int i=0;i<NLim;i++){
91 if( ASS((
Evalx(Tre)-0.)) < PrecMinimo){
94 Tre = Due - (Due - Uno)/(
Df(Due,Delta)-
Df(Uno,Delta))*
Df(Due,Delta);
102 double Uno=a;
double Due=b;
double Tre=0.;
104 double Delta = (b-a)/dIncr;
107 CONTROLLA = fopen(
"RegulaFalsi.dat",
"w");
108 for(
int i=0;i<NPassi;i++){
109 if( ASS(
Evalx(Tre)) < PrecMinimo){
112 else if( ASS(
Evalx(Due)) < PrecMinimo){
116 else if( ASS(
Evalx(Uno)) < PrecMinimo){
121 if(
Evalx(Due) < 0. &&
Evalx(Uno + Delta) > 0.){
124 if(
Evalx(Due - Delta) < 0. &&
Evalx(Uno) > 0.){
132 if(
Evalx(Due) > 0. &&
Evalx(Uno+Delta) < 0.){
135 if(
Evalx(Due - Delta) > 0. &&
Evalx(Uno) < 0.){
143 Uno += (b-a) / dIncr;
150 Tre = (Due + Uno)/2.;
154 if( !(ASS((
Evalx(Tre)-0.)) < PrecMinimo)){
167 double Uno=a,Due =0.,Tre=0.;
170 CONTROLLA = fopen(
"Newton.dat",
"w");
171 for(
int i=0;i<NPassi;i++){
172 if( ASS((
Evalx(Tre))) < PrecMinimo){
177 q =
Evalx(Uno) - m*Uno;
179 printf(
"%d) %lf %lf %lf\n",i,Uno,Due,
Evalx(Tre));
180 fprintf(CONTROLLA,
"%lf %lf\n",Tre,
Evalx(Tre));
183 if( !(ASS((
Evalx(Tre)-0.)) < PrecMinimo)){
184 printf(
"Calculation failed\n");
196 return 1./(Scarto*sqrt(DUE_PI))*exp(- .5*SQR((x-Media)/Scarto) );
199 double Delta = (b-a)/(
double)NPassi;
201 for(
int i=0;a+((double)i)*Delta<b;i+=3){
202 Risp += 3*Delta*(
Gauss(0.,Scarto,a+Delta*i)+3*
Gauss(0.,Scarto,a+Delta*(i+1))+3*
Gauss(0.,Scarto,a+Delta*(i+2))+
Gauss(0.,Scarto,a+Delta*(i+3)) )/8;
211 for(
int n=0;n<NMass;n++){
214 Norm = 1./sqrt(Norm);
215 for(
int n=0;n<NMass;n++){
221 for(
int n=0;n<NMass;n++){
227 for(
int n=0;n<NMass;n++){
232 if(n < 0) { printf(
"Il fattoriale di numeri negativi non ha senso\n");
return 0;}
233 if( n == 0 )
return 1;
235 for(
int i=n;i>0;i--){
246 double Moltx = Volte >= 0 ? x : 1./x;
247 for(
int v=0;v<Volte;v++)
255 for(
int n=0;n<NMax;n++){
259 return Ord>=0 ? Risp :
Elevato(-1.,Ord)*Risp;
262 double Angolo = Ord*.5*DUE_PI+.0001;
263 return Bessel(Val,Ord)*(cos(Angolo) -
Elevato(-1.,Ord))/sin(Angolo);
266 if( Val > (
double)Ord +1.)
267 return sqrt((2./(PI*Val))) *cos( Val- (2.*Ord+1.)*PI*.25);
273 return 2./PI*log(Val);
274 if(Val > (
double) Ord+1.)
275 return sqrt(2./(PI*Val))*sin(Val-(2.*Ord+1.)*PI*.25);
280 return (n%2)==1 ? -1. : 1.;
283 double Risp=2.*x*x*x - 3.*(a+1.)*x*x-3.*a*a+1.;
288 double Risp= -a*x*x + 1. + 4./3.*PI*a;
294 double Num = 2.*DUE_PI*QUAD(RadNp)*sin(Theta);
295 double Den = QUAD(RadNp) + QUAD(Rad+RadNp) - 2.*(Rad+RadNp)*RadNp*cos(Theta);
299 return pow(1./(r-r_np),9.) - pow(1./(r-r_np),3.);
302 double ThetaMax = PI;
303 double ThetaMin = 0.;
304 double ThetaDelta = (ThetaMax-ThetaMin)/100.;
306 for(
double Theta = ThetaMin;Theta<ThetaMax;Theta+=ThetaDelta){
307 Risp += ThetaDelta*.5*(
LJHamaker(Rad,RadNp,Theta) +
LJHamaker(Rad,RadNp,Theta+ThetaDelta) );
312 double RadNpDelta = (RadNpMax-RadNpMin)/100.;
314 for(
double RadNp = RadNpMin;RadNp<RadNpMax;RadNp+=RadNpDelta){
321 double Potenziale(
double Dist,
double RadNp){
322 double Rad = Dist + RadNp;
323 double Pre1 = 2./(12.*Rad);
324 double Post1 = RadNp / CUB(Rad+RadNp) + RadNp/CUB(Rad-RadNp);
325 double Pre2 = 1./(12.*Rad);
326 double Post2 = 1./QUAD(Rad+RadNp) - 1./QUAD(Rad+RadNp);
327 return PI*(Pre1*Post1 + Pre2*Post2);
329 double Potenziale2(
double Dist,
double RadNp){
330 double Rad = Dist + RadNp;
331 double Pre1 = -( QUAD(RadNp) - QUAD(Rad) )/(4.*Rad);
332 double Post1 = 1./QUAD(QUAD(Rad+RadNp)) - 1./QUAD(QUAD(Rad-RadNp));
333 double Pre2 = -2./(3.);
334 double Post2 = 1./CUB(Rad+RadNp) - 1./CUB(Rad+RadNp);
335 double Pre3 = 1./(2.*Rad);
336 double Post3 = 1./QUAD(Rad+RadNp) - 1./QUAD(Rad+RadNp);
337 return PI*(Pre1*Post1 + Pre2*Post2 + Pre3*Post3);
340 double RadNpMin = 0.;
341 double RadNpMax = .001;
342 double RadNpDelta = (RadNpMax - RadNpMin)/20.;
345 double RadDelta = (RadMax-RadMin)/100.;
346 char *FileName = (
char *)calloc(60,
sizeof(
char));
347 double RadNp = RadNpMax;
350 sprintf(FileName,
"Potential%0.2f.dat",RadNp);
351 FILE *POT = fopen(FileName,
"w");
352 for(
double Rad = RadMin;Rad < RadMax;Rad += RadDelta){
353 fprintf(POT,
"%lf %g %g %g \n",Rad,
LJHamaker(Rad,RadNp),
LJHamakerCum(Rad,RadNpMin,RadNp),Potenziale(Rad,RadNp) );
double Ypsilon
External parameter to calculate the contact angle.
void SquareGradient(double *st, double *sw, int NMass)
Square of the gradient.
void DerO4(double *st, double *sw, int NMass)
Derivate O(4) of.
void NormalizeVect(double *st, int NMass)
Normalize.
double Integrazione(double *Punti, double *sw, int NMass)
Integral of.
int Zeri(double a, double b, double *Radici, int NRadici)
Find the.
double sLim
Superior limit.
double fProva(double x)
Trial function.
double QuasiBessel(double Val, int Ord)
A faster Bessel.
void Derivata(double *st, double *sw, int NMass)
Derivate of.
double Bessel(double Val, int Ord)
Bessel function.
int IfRis
If the zero was founds.
void Modulo(double *st, double *sw, int NMass)
Compute the modulus.
double QuasiNeumann(double Val, int Ord)
A faster Neumann.
double Df(double x, double Delta)
Boh.
double iLim
Iferior limit.
double Zero
Point of the zero.
double LJ39(double r, double r_np)
Integration of the LJ 6 term.
double ContactAngle(double x)
Definition of the contact angle.
double WeightFunction2(double x, double a)
Definition of a weighting function.
double PreFact
External parameter in the definition of the contact angle.
RADICE Newton(double a)
Use Newton to find the roots.
void IntegraA3()
Perform a integration of a LJ6 Potential.
double Gauss(double Media, double Scarto, double x)
Gaussian.
double Elevato(double x, int Volte)
Integer power.
double Estremo(double a, double b)
Other algorithm to find the roots.
Where a root was searched.
double F(double TD, double T)
Boh.
double Gamma(int n)
Euler's gamma.
double Evalx(double x)
Pointer to a generic function.
double Norm(double *st, int NMass)
Norm of an array.
double LJHamaker(double r, double r_np, double theta)
Integration of the LJ 6 term.
double Fattoriale(int n)
Compute the factorial.
double IntegrazioneGauss(double a, double b, double Scarto)
Itegrate a Gaussian.
RADICE RegulaFalsi(double a, double b)
Use regula falsi algorithm to find the roots.
double Neumann(double Val, int Ord)
Neumann function.
double Segno(int n)
Sign of -^n.
double WeightFunction(double x, double a)
Definition of a weighting function.
double LJHamakerCum(double Rad, double RadNpMin, double RadNpMax)
Integrate over r_np up to RadNp.