Aller au contenu

Mathc initiation/a600

Un livre de Wikilivres.


SommaireUtilise la commande "Retour en Arrière" de ton navigateur.


Installer ce fichier dans votre répertoire de travail.

x_fcoef.h
/* ---------------------------------- */
/* save as x_fcoef.h                  */
/* ---------------------------------- */
/* ---------------------------------- */
double fourier_a0(
double (*P_f)(double x),
double a,
double b
)
{
   int i = 0;
double m = 0.;
double M = 0.;

 for(i = 0; i <= LOOP; i++)
 {
       if(i ==0 || i== LOOP){m = 1.;}
  else if(fmod(i,2) ==    0){m = 2.;}
  else                      {m = 4.;}

  M += m * (*P_f)(a + i*(b-a)/LOOP);
 }

  return( ((b -a)*M) / (3*LOOP) );
}
/* ---------------------------------- */
/* ---------------------------------- */
double fourier_an(
double (*P_f)(double t),
double a,
double b,

double omega,

double n
)
{
   int i = 0;
double m = 0.;
double M = 0.;

double t;

 for(i = 0; i <= LOOP; i++)
 {
       if(i ==0 || i== LOOP){m = 1.;}
  else if(fmod(i,2) ==    0){m = 2.;}
  else                      {m = 4.;}

  t     = (a + i*(b-a)/LOOP);
    
  M += m * (*P_f)(t)*cos(n*omega*t);
 }

  return( ((b -a)*M) / (3*LOOP) );
}
/* ---------------------------------- */
/* ---------------------------------- */
double fourier_bn(
double (*P_f)(double t),
double a,
double b,

double omega,

double n
)
{
   int i = 0;
double m = 0.;
double M = 0.;

double t;

 for(i = 0; i <= LOOP; i++)
 {
       if(i ==0 || i==LOOP){m = 1.;}
  else if(fmod(i,2) ==   0){m = 2.;}
  else                     {m = 4.;}

  t     = (a + i*(b-a)/LOOP);
    
  M += m * (*P_f)(t)*sin(n*omega*t);
 }

  return( ((b -a)*M) / (3*LOOP) );
}
/* ---------------------------------- */
/* ---------------------------------- */