clear all close all % Problem domain, in meters. X = 2; Y = 2; D = 0.05; % Problem domain, in cells. NX = X/D; NY = Y/D; V_last = zeros(NY+1,NX+1); V_next = zeros(NY+1,NX+1); V_last(20:22, 14:16) = 1; V_last(20:22, 24:26) = -1; ITERATIONS = 400; for i=1:ITERATIONS % Compute next voltage. for iy=2:NY for ix=2:NX V_next(iy,ix) = 1/4* ( V_last(iy-1,ix) + V_last(iy+1,ix) + V_last(iy,ix-1) + V_last(iy,ix+1) ); end end % Overwrite conductors with their impressed potentials. V_next(20:22, 14:16) = 1; V_next(20:22, 24:26) = -1; % Iterate. V_last = V_next; end x_axis = linspace(0,X, NX + 1); y_axis = linspace(0,Y, NY + 1); [x,y] = meshgrid(x_axis, y_axis); [Ex,Ey] = gradient(-V_last,D,D); contour(x,y,V_last,20); hold on quiver(x,y,Ex,Ey); set(gcf,'Color',[1 1 1]); xlabel ('x, meters'); ylabel ('y, meters'); title ('ECE 311 - HW 7, Problem 1. Two conductor case.'); hold off axis equal;