#include #include #include #include #define EPS 3.0e-14 #define MAXIT 10 long double gammln(long double xx) { double x,y,tmp,ser; static double cof[6]={76.18009172947146,-86.50532032941677,24.01409824083091,-1.231739572450155,0.1208650973866179e-2,-0.5395239384953e-5}; int j; y=x=xx; tmp=x+5.5; tmp-=(x+0.5)*log(tmp); ser=1.000000000190015; for (j=0;j<=5;j++) ser +=cof[j]/++y; return -tmp+log(2.5066282746310005*ser/x); } void gaulag(double x[], double w[], int n, float alf) { long double gammln(long double xx); //void nrerror(char error_text[]); int i,its,j; long double ai; double p1,p2,p3,pp,z,z1; for (i=1;i<=n;i++) { if (i==1) { z=(1+alf)*(3+0.92*alf)/(1+2.4*n+1.8*alf); } else if (i==2) { z+=(15+6.25*alf)/(1+0.9*alf+2.5*n); } else { ai=i-2; z+=((1+2.55*ai)/(1.9*ai)+1.26*ai*alf/(1+3.5*ai))*(z-x[i-2])/(1+0.3*alf); } for (its=1;its<=MAXIT;its++) { p1=1; p2=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) {printf("Zu viele Iterationen in gaulag\n");exit(1);} x[i]=z; w[i]=-exp(gammln(alf+n)-gammln((long double)n))/(pp*n*p2); } } void main() { FILE *stream; int n,i; int j; double s; float alf; char datei[50]; printf("n: "); scanf("%d",&n); printf("alpha: "); scanf("%f",&alf); printf("Ausgabedateiname: "); scanf("%s",datei); if ((stream=fopen(datei,"w"))==NULL) { printf("Kann Datei nicht öffnen!!!"); exit(1); } double x[100];double w[100]; gaulag(x,w,n,alf); for (i=1;i<=n;i++) { printf("%d: x %lf w %lf\n",i,x[i],w[i]); fprintf(stream,"%d: x %lf w %lf\n",i,x[i],w[i]);} s=0; for (j=1;j<=n;j++) { s+=w[j]*(1/(1-exp(-x[j]))); } printf("Ergebinis: %lf\n",s); fprintf(stream,"Ergebinis: %lf",s); }