Home

/*_________________________________________________________


Tests on functions with prescribed local regularity


Generalized Weierstrass functions


_________________________________________________________*/


#include <stdlib.h>

#include <math.h>

#define X_MIN -0.5

#define X_MAX 0.5

#define Abs(x) ((x) < 0 ? -(x) : (x))

#define MAX(x,y) ((x)>(y)?(x):(y))

#define MIN(x,y) ((x)<(y)?(x):(y))



// Generalized Weierstrass where the Holder exponent h(x) = Abs(x)

double WeierX(double);


// "Unfavourable" Holder profile

double ProfilU(double);

// Generalized Weierstrass where the Holder exponent h(x) = U(x)

double WeierU(double);

// Oscillation-normalised generalized Weierstrass where h(x) = U(x)

double FonctionU(double);


// "Favourable" Holder profile

double ProfilN(double);

// Generalized Weierstrass where the Holder exponent h(x) = N(x)

double WeierN(double);

// Oscillation-normalised generalized Weierstrass where h(x) = N(x)

double FonctionN(double);



// The number of steps we actually compute in infinite sums

#define ITER 50





// ----------------------------------------

// Generalized Weierstrass where the Holder exponent h(x) = Abs(x)

// W(x) is defined for x in [-0.5, 0.5]


double WeierX(double x) {

double val = 0;

double b = 2.;

double h=0;

int k;


// Compute the desired local Holder exponent

h = Abs(x);

// Compute the infinite sum of 2^{-k.h(x)}.sin(2^k . x)

for (k=0;k<ITER;k++)

val += pow(b,-(double)k*h) * sin(pow(b,(double)k)*x);


return val ;

}





// ----------------------------------------

// Unfavourable Holder profile

// U(x) is 0.1 close to 0, 0.9 elsewhere


double ProfilU(double x) {

if (Abs(x)><0.2) return 0.1 ;

else return 0.9 ;

}



// ----------------------------------------

// Generalized Weierstrass where the Holder exponent h(x) = U(x)

// Wu(x) is defined for x in [-0.5, 0.5]


double WeierU(double x) {

double val= 0;

double b = 2.;

double h=0.;

int k;

// Compute the desired local Holder exponent

h = ProfilU(x);


// Compute the infinite sum of 2^{-k.h(x)}.sin(2^k . x)

for (k=0;k<ITER;k++)

val += pow(b,-(double)k*h) * sin(pow(b,(double)k)*x);


return val ;

}



// ----------------------------------------

// Oscillation-normalised generalized Weierstrass

// Fu(x) is defined for x in [-0.5, 0.5], and also has h(x) = U(x)


double FonctionU(double x) {

// Diameter of the neighborhood used for the normalisation

double epsilon = 0.05;

// Number of samples in the neighborhood

int Kmax = 10;


// Mean on the neighborhood

double mean = 0.;

// Max variation on the neighborhood

double varia = 0.;


double res =0;

int k;


// Computing the function's mean on the neighborhood

for (k=-Kmax;k<Kmax;k++) mean += WeierU(x+(k*epsilon)/Kmax);

mean = mean/(2.*Kmax);

// Computing the function's maximum variation on the neighborhood

for (k=-Kmax;k<Kmax;k++) varia = MAX(varia,WeierU(x+ k*epsilon/Kmax) - mean);


// Normalising the Weierstrass function at x, and adding the global quadratic trend

if (varia) res = 2-4*x*x - 0.1*Abs((WeierU(x) - mean)/varia);

return res ;

}





// ----------------------------------------

// Favourable Holder profile

// N(x) is 0.9 close to 0, and 0.1 elsewhere


double ProfilN(double x) {

if (Abs(x)><0.2) return 0.9 ;

else return 0.1 ;

}



// ----------------------------------------

// Generalized Weierstrass where the Holder exponent h(x) = N(x)

// Wn(x) is defined for x in [-0.5, 0.5]


double WeierN(double x) {

double val= 0;

double b = 2.;

double h=0.;

int k;

// Compute the desired local Holder exponent

h = ProfilN(x);


// Compute the infinite sum of 2^{-k.h(x)}.sin(2^k . x)

for (k=0;k<ITER;k++)

val += pow(b,-(double)k*h) * sin(pow(b,(double)k)*x);


return val ;

}



// ----------------------------------------

// Oscillation-normalised generalized Weierstrass

// Fn(x) is defined for x in [-0.5, 0.5], and also has h(x) = N(x)


double FonctionN(double x) {

// Diameter of the neighborhood used for the normalisation

double epsilon = 0.05;

// Number of samples in the neighborhood

int Kmax = 10;


// Mean on the neighborhood

double mean = 0.;

// Max variation on the neighborhood

double varia = 0.;


double res =0;

int k;


// Computing the function's mean on the neighborhood

for (k=-Kmax;k<Kmax;k++) mean += WeierN(x+(k*epsilon)/Kmax);

mean = mean/(2.*Kmax);

// Computing the function's maximum variation on the neighborhood

for (k=-Kmax;k<Kmax;k++) varia = MAX(varia,WeierN(x+ k*epsilon/Kmax) - mean);


// Normalising the Weierstrass function at x, and adding the global quadratic trend

if (varia) res = 2-4*x*x - 0.1*Abs((WeierN(x) - mean)/varia);

return res ;

}








-- EvelyneLutton - 19 May 2006


home