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

Computation of potential field tex2html_wrap_inline563

Complex ErfR(d3vec r,double sigma)
Output:

Input:

The analytic solution to Poisson's equation

displaymath567

for a Gaussian charge distribution of width tex2html_wrap_inline569

displaymath571

where tex2html_wrap_inline573 , is

displaymath575

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

To directly compare your computational solution for phi in part 2.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
Fri Apr 14 12:12:49 EDT 2000