This is my program to solve a simple laplace problem where a Voltage of 100V is applied at the top and all other bounderies are 0V. The Matrix outputs the correct values (in var "z"). And the potential distribution seems right. The Problem is that when I use the quiver function to plot the E-Field lines then they originate from the bottom boundary (at 0V) and end at sides and the Top. But the Fields should originate from the top at (100v) and end at the sides and the bottom. I can't figure out what went wrong so any help would be appreciated. Thanks.
%array
u = zeros(50);u(1,:)=100;z = u;%loop
for i =1:500 for i = 2: size(z,1)-1; for j = 2 : size(z,1)-1 z(i,j) = (z(i-1,j)+z(i+1,j)+z(i,j-1)+z(i,j+1))/4; end end % getframe
figure(1) endimagesc(z); figure(2)[ex,ey] = gradient(z);axis xyquiver(-ex,-ey,3);
Best Answer