1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
//====================LIBRARY===================================================
#include <stdio.h>
#include <math.h>
#include <conio.h>
#define EPS 3.0e-14
#define MAXIT 10
//====================MAIN======================================================
double q,dk;
double ftest_k(double k);
double test();
void gaulegf(double x1, double x2, double x[], double w[], int n);
int main()
{
FILE *output;
output=fopen ("testtp.dat","w+" );
printf(" %f\n ",test());
fprintf(output, " %f\n",test());
fclose(output);
printf("\nfin\n");
getch();
}
//====================THE TEST FUNCTION===============================
void gaulag(float x[],float w[],int n,float alf)
{
float gammln(float xx);
void nrerror(const char error_text[]);
int i,its,j;
float ai;
double p1,p2,p3,pp,z,z1;
for (i=1;i<=n;i++) {
if (i == 1) {
z=(1.0+alf)*(3.0+0.92*alf)/(1.0+2.4*n+1.8*alf);
} else if (i == 2) {
z += (15.0+6.25*alf)/(1.0+0.9*alf+2.5*n);
} else {
ai=i-2;
z += ((1.0+2.55*ai)/(1.9*ai)+1.26*ai*alf/
(1.0+3.5*ai))*(z-x[i-2])/(1.0+0.3*alf);
}
for (its=1;its<=MAXIT;its++) {
p1=1.0;
p2=0.0;
for (j=1;j<=n;j++) {
p3=p2;
p2=p1;
p1=((2*j-1+alf-z)*p2-(j-1+alf)*p3)/j;
}
pp=(n*p1-(n+alf)*p2)/z;
z1=z;
z=z1-p1/pp;
if (fabs(z-z1) <= EPS) break;
}
if (its > MAXIT) nrerror(" too many iterations in gaulag ");
x[i]=z;
w[i] = -exp(gammln(alf+n)-gammln((float)n))/(pp*n*p2);
}
}
#undef EPS
#undef MAXIT
double ftest_k(double k)
{ double kq;
kq=k;
return kq;
}
double test()
{
int n,i, j;
double sum;
float k[2000], w[2000], alf;
i=100.;
gaulag(k, w, n, alf);
sum = 0.0;
for(j=1; j<=i; j++)
{
sum = sum + w[j]*ftest_k(k[j]);
}
return sum;
}
|