Changeset 3514 in Sophya for trunk/SophyaLib/NTools
- Timestamp:
- Aug 8, 2008, 4:17:50 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/NTools/nbmath.c
r2639 r3514 1121 1121 | w[] = valeur des coefficients associes 1122 1122 | 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 1127 1126 | - Voir la fonction Integ_Fun pour un calcul d'ordre 8 1128 1127 -- … … 1131 1130 { 1132 1131 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 1134 1133 1135 1134 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 1141 1140 p1=1.0; 1142 1141 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 1144 1143 p3=p2; 1145 1144 p2=p1; 1146 1145 p1=((2.0*j-1.0)*z*p2-(j-1.0)*p3)/j; 1147 1146 } 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 1148 1149 pp=n*(z*p1-p2)/(z*z-1.0); 1149 1150 z1=z; 1150 z=z1-p1/pp; 1151 z=z1-p1/pp; // Newton's method 1151 1152 } 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 1156 1157 } 1157 1158 }
Note:
See TracChangeset
for help on using the changeset viewer.