1 |
foucault |
27 |
//---------------------------------------------------------------------------
|
2 |
|
|
|
3 |
|
|
#include <math.h>
|
4 |
|
|
#include <stdio.h>
|
5 |
|
|
#define EPS 3.0e-11
|
6 |
|
|
|
7 |
|
|
#pragma hdrstop
|
8 |
|
|
|
9 |
|
|
#include "gestionversion.h"
|
10 |
|
|
#include "ot_quadrature_gauss.h"
|
11 |
|
|
//---------------------------------------------------------------------------
|
12 |
|
|
#pragma package(smart_init)
|
13 |
|
|
|
14 |
|
|
void OT_QUADRATURE_GAUSS::gauss_legendre_points(double x1, double x2, double x[], double w[], int n)
|
15 |
|
|
{
|
16 |
|
|
int m,j,i;
|
17 |
|
|
double z1,z,xm,xl,pp,p3,p2,p1;
|
18 |
|
|
m=(n+1)/2;
|
19 |
|
|
xm=0.5*(x2+x1);
|
20 |
|
|
xl=0.5*(x2-x1);
|
21 |
|
|
for (i=1;i<=m;i++) {
|
22 |
|
|
z=cos(M_PI*(i-0.25)/(n+0.5));
|
23 |
|
|
do {
|
24 |
|
|
p1=1;
|
25 |
|
|
p2=0;
|
26 |
|
|
for (j=1;j<=n;j++) {
|
27 |
|
|
p3=p2;
|
28 |
|
|
p2=p1;
|
29 |
|
|
p1=((2*j-1)*z*p2-(j-1)*p3)/j;
|
30 |
|
|
}
|
31 |
|
|
pp=n*(z*p1-p2)/(z*z-1);
|
32 |
|
|
z1=z;
|
33 |
|
|
z=z1-p1/pp;
|
34 |
|
|
} while (fabs(z-z1) > EPS);
|
35 |
|
|
x[i]=xm-xl*z;
|
36 |
|
|
x[n+1-i]=xm+xl*z;
|
37 |
|
|
w[i]=2*xl/((1-z*z)*pp*pp);
|
38 |
|
|
w[n+1-i]=w[i];
|
39 |
|
|
}
|
40 |
|
|
} |