Changeset 3514 in Sophya for trunk/SophyaLib/NTools


Ignore:
Timestamp:
Aug 8, 2008, 4:17:50 PM (17 years ago)
Author:
cmv
Message:

3.14159 _> M_PI + commentaires dans nbgauleg cmv 08/08/2008

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/NTools/nbmath.c

    r2639 r3514  
    11211121|  w[] = valeur des coefficients associes
    11221122| REMARQUES:
    1123 |  - x et w doivent au moins etre dimensionner a n.
    1124 |  - l'integration est rigoureuse si sur l'intervalle d'integration
    1125 |    la fonction f(x) peut etre approximee par un polynome
    1126 |    de degre 2*m (monome le + haut x**(2*n-1) )
     1123|  - x et w doivent au moins etre dimensionnes a n.
     1124|  - l'integration est exacte sur l'intervalle [x1,x2]
     1125|    si f(x) est un polynome de degre inferieur ou egal a 2*n-1
    11271126|  - Voir la fonction Integ_Fun pour un calcul d'ordre 8
    11281127--
     
    11311130{
    11321131   int m,j,i;
    1133    double z1,z,xm,xl,pp,p3,p2,p1;
     1132   double z1,z,xm,xl,pp,p3,p2,p1; // Need high precision
    11341133
    11351134   m=(n+1)/2;
    1136    xm=0.5*(x2+x1);
    1137    xl=0.5*(x2-x1);
    1138    for (i=1;i<=m;i++)  {
    1139       z=cos(3.141592654*(i-0.25)/(n+0.5));
    1140       do {
     1135   xm=0.5*(x2+x1);     // The root are symetric in the intervalle
     1136   xl=0.5*(x2-x1);     // we just need to find half of them
     1137   for (i=1;i<=m;i++)  {   // Loop over the desired root
     1138     z=cos(M_PI*(i-0.25)/(n+0.5));  // Starting with the approx for the i-ieme root
     1139     do {       // Entering the main loop of refinement by Newton's method
    11411140         p1=1.0;
    11421141         p2=0.0;
    1143          for (j=1;j<=n;j++) {
     1142         for (j=1;j<=n;j++) { // Loop up the reccurence relation to get the Legendre polynomial at z
    11441143            p3=p2;
    11451144            p2=p1;
    11461145            p1=((2.0*j-1.0)*z*p2-(j-1.0)*p3)/j;
    11471146         }
     1147         // p1 is now the desired Legendre polynomial. We next compute pp, its derivative,
     1148         // by a standard relation involving also p2, the polynomial of one lower order
    11481149         pp=n*(z*p1-p2)/(z*z-1.0);
    11491150         z1=z;
    1150          z=z1-p1/pp;
     1151         z=z1-p1/pp;   // Newton's method
    11511152      } while (fabs(z-z1) > EPS_gauleg);
    1152       x[i-1]=xm-xl*z;
    1153       x[n-i]=xm+xl*z;
    1154       w[i-1]=2.0*xl/((1.0-z*z)*pp*pp);
    1155       w[n-i]=w[i-1];
     1153      x[i-1]=xm-xl*z;                   // Scale the root to the desired interval,
     1154      x[n-i]=xm+xl*z;                   // and put in its symetric counterpart.
     1155      w[i-1]=2.0*xl/((1.0-z*z)*pp*pp);  // Compute the weight
     1156      w[n-i]=w[i-1];                    // and its symetric counterpart
    11561157   }
    11571158}
Note: See TracChangeset for help on using the changeset viewer.