#include #include #define EPS 3.0e-11 void gauleg(float x1,float x2, double x[],double w[],int n) { int m,j,i; double z1,z,xm,xl,pp,p3,p2,p1; m=(n+1)/2; xm=0.5*(x2+x1); xl=0.5*(x2-x1); for (i=1;i<=m;i++) { z=cos(M_PI*(i-0.25)/(n+0.5)); do { p1=1; p2=0; for (j=1;j<=n;j++) { p3=p2; p2=p1; p1=((2*j-1)*z*p2-(j-1)*p3)/j; } pp=n*(z*p1-p2)/(z*z-1); z1=z; z=z1-p1/pp; } while (fabs(z-z1) > EPS); x[i]=xm-xl*z; x[n+1-i]=xm+xl*z; w[i]=2*xl/((1-z*z)*pp*pp); w[n+1-i]=w[i]; } } double F(double x,int xp,int yp,double y[],double w[],int n) { double s;int i; for (i=1;i<=n;i++) { s+=w[i]*1/sqrt(pow((x-xp),2)+pow((y[i]-yp),2)); /*printf("%le %d %d %le\n",w[i],xp,yp,y[i]);*/} //printf ("%le %le\n",x,s); return s; } void main() { FILE *stream; int n,i; int xp,yp; double s=0,s2=0; char datei[50]; printf("xp: ");scanf("%d",&xp); printf("yp: ");scanf("%d",&yp); printf("n: "); scanf("%d",&n); //printf("Ausgabedateiname: "); scanf("%s",datei); double x[n];double w[n]; /*if ((stream=fopen(datei,"w"))==NULL) { printf("Kann Datei nicht öffnen!!!"); exit(1); }*/ gauleg(-1,1,x,w,n); for (i=1;i<=n;i++) { s2=F(x[i],xp,yp,x,w,n); s+=w[i]*s2;printf("%le",s2);} printf("\n%1.10lf\n",s); //fprintf(stream,"%1.10le",s); }