//this program calculate the electric potential for a uniform square at [-1,1]X[-1,1] // this is based on assg2team1.c - integration routinue used is Simpson's rule //NOTE: if the observation point (x_p,y_p) is within the charge distribution, the // integrant is singular at that point but the integral remains integrable. #include #include //accuracy for integrator #define EPS 1.0e-4 #define MaxN 100000000 double pi; double Ekernal(double xx,double yy,double xxp,double yyp); double integrateSR(double xxp,double yyp,double tol); double innerSR(double xx,double xxp,double yyp,double tol); main() { int i,j; double xp,yp; int NNx,NNy; double stepx,stepy; double offset; double phi; FILE *outfile; pi=4.0*atan(1.0); offset=1e-3*pi; outfile=fopen("charge.dat","w"); printf("Number of pixel within [-4,4]X[-4,4]\n"); printf("\tNx:\n"); scanf("%d",&NNx); printf("\tNy:\n"); scanf("%d",&NNy); stepx=8.0/NNx; stepy=8.0/NNy; xp=-4.0+offset; yp=-4.0-offset; for(i=0;itol && Nxtol && Ny