/* From: "A SURVEY OF COMPUTATIONAL PHYSICS" by RH Landau, MJ Paez, and CC BORDEIANU Copyright Princeton University Press, Princeton, 2008. Electronic Materials copyright: R Landau, Oregon State Univ, 2008; MJ Paez, Univ Antioquia, 2008; & CC BORDEIANU, Univ Bucharest, 2008 Support by National Science Foundation */ // laplaceAnal.c Analytic solution of Laplace eqnt #include #include #include /*___________________________________________________________ | Solves Laplace equation in a two dimensional plate | | v(i,j) is the potential at grid point (i,j) | | i: x position ,i=1,2,..,101 | | j: y position ,j=1,2,..,101 | | ngrid: number of grid points in one side | | nitl: number of iterations for numerical solution | | van(i) computed with the analytical solution | | i= 1,2,...,11 | |__________________________________________________________|*/ FILE *fp; void initial(int ngrid,double v[101][101]) { /* Initialize values for the potential */ int i,j,k; for(i=0;i0;j=j-10){ for(i=0;i1;j=j-2){ yova=dincr*(j-1); xova=0.00; /*computes each row (x axis) */ for(i=0;i<41;i++){ sum =0.0; /*each point (x,y) is computed summing 40000 terms */ for(n=nsum;n>=1;n=n-2){ pin=n*pi; xfc=pin*xova; dexnpi=exp(-pin*(yova+1.00)); if(dexnpi<(1.0e-10))dexnpi=0.00; facsin=exp(pin*(yova-1.00))-dexnpi; dex2npi=exp(-2*pin); if(dex2npi<(1.0e-10))dex2npi=0.0; facden=1.00-dex2npi; sum=sum+sin(xfc)*facsin/(facden*n); } sum=sum*fact; van[i]=sum; xova=2.00*dincr+xova; } /* each row is printed. */ for(ii=0;ii<41;ii++){ fprintf(fp,"\n%7.2f",van[ii]); } fprintf(fp,"\n"); } return; } void main() { double v[101][101]; int ngrid,nitl; /* ngrid=101; nitl=15500; */ fp=fopen("vplate1.dat","w"); /*in file platepot.dat, the data for graphing*/ /*initial potential */ /*initial (ngrid,v); //the potential everywhere is calculated */ /*average(ngrid,nitl,v); */ /*the analytical solution is found*/ analytc(); fclose(fp); }