Complex ErfR(d3vec r,double sigma)Output:
- ErfR:
![]()
Input:
- sigma: rms width
- r: d3vec with components r.x, r.y, r.z
Important note for Windows users: The standard error function
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
for a Gaussian charge distribution of width
where
, is
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);