next up previous contents
Next: For fun: Up: Potential from a sum Previous: Debugging:

Computation of potential field tex2html_wrap_inline624

Complex ErfR(d3vec r,double sigma)
Output:

Input:

Important note for Windows users: The standard error function tex2html_wrap_inline628 is not part of the math library for Visual Studio C++. You may down-load the source code for the erf() function from the course web site at http://www.muchomas.lassp.cornell.edu/P480/s_erf.c.

The analytic solution to Poisson's equation

displaymath630

for a Gaussian charge distribution of width tex2html_wrap_inline632

displaymath634

where tex2html_wrap_inline636 , is

displaymath638

Write a function of the above prototype to evaluate this function.

To directly compare your computational solution for phi in part 3.2.2 with the analytic solution, use evalr and ErfR to construct pvectors phi1 and phi2 containing the analytic solutions corresponding to the charge distributions rho1 and rho2. The analytic solution for rho=rho1-rho2 is then phianal=phi1-phi2. (Remember the principle of superposition!)

As discussed in class, your computational solution, phi, will differ from the analytic result phianal by an arbitrary constant shift in the potentials. Use the following code fragment to (a) compute the shift, (b) adjust the potentials by adding the correct shift, and (c) evaluate the remaining error:

  pvector error(i3vec(n,n,n),d3vec(d,d,d));

  shift=real(sum(phi-phianal)/N);
  error=phi-phianal-shift*ones;

  printf("Average shift between phi and phianal: %e\n",shift);
  printf("rms error in phi: %e\n",(error^error)/N);




Tomas Arias
Sun Apr 15 19:43:40 EDT 2001