I am trying to compute the electric potential at point (x,y,z) by solving the 3D Poisson equation below using finite difference method.
I have the charge densities at various positions of (x,y,z).
Below are the boundary condtions;
- Dirichlet boundary condition are applied at the top and bottom of the planes of the rectangular grid.
- Electric potential is to be incorporated by setting and , where h is the height of the simulation box.
- Neumann boundary conditions are also enforced at the remaining box interfaces by setting at faces with constant x , at faces with constant y, and at faces with constant z.
I did the implementation of the boundary conditions with this code and I would want to ascertain if
the implementation of the boundary condtions is right.
x1 = linspace(0,10,20);
y1 = linspace(0,10,20);
z1 = linspace(0,10,20);
V = zeros(length(x1),length(y1),length(z1));
V(:,end,end) = 0;
V(end,:,end) = 0;
V(end,end,:) = 0;
V(:,1,1) = 0;
V(1,:,1) = 0;
V(1,1,:) = 0;
V(:,:,1) = 0;
V(:,:,end) = -40*z1(end);
i = 2:length(x1)-1;
j = 2:length(y1)-1;
k = 2:length(z1)-1;
V(i+1,j,k) = V(i-1,j,k);
V(i,j+1,k) = V(i,j-1,k);
V(i,j,k+1) = V(i,j,k-1);