/* ************************************************************************ * laplace.c: Solution of Laplace equation with finite differences * * * * comment: Output data is saved in 3D grid format used by gnuplot * ************************************************************************ */ #include #include #define maxx 40 /* number of grid points */ #define maxy 40 /* number of grid points */ main() { double p[maxx][maxy], pnew[maxx][maxy], dp, dpmax, omega; int i, j, iter; FILE *output; /* save data in laplace.dat */ FILE *file; /* save data in laplace_dp.dat */ output = fopen("laplace.dat","w"); file = fopen("laplace_dp.dat","w"); for(i=0; i dpmax) dpmax=fabs(dp); } } for(i=1; i<(maxx-1); i++) /* x-direction */ { for(j=1; j<(maxy-1); j++) /* y-direction */ { p[i][j] = pnew[i][j]; } } fprintf(file, "%d\t%f\n",iter,dpmax); } for (i=0; i