You are on page 1of 1

Code using script in MATLAB

clc
close all; clear all;
%Assigning parameter
%v(i,j) = potential coordinate
ni = 300; %ni = number of iterations
nx = 200; %nx = number of x grids
ny = 200; %ny = number of y grids
va = 80000;
vb = 160000;

v = zeros (nx,ny); %set al potential equal to zero
for i=5:9 %set potential at certain coordinate
v(i,40) = va;
v(i,44) = va;
end
for j=40:44 %set potential at certain coordinate
v(5,j) = va;
v(9,j) = va;
end
for i=13:20 %set potential at certain coordinate
v(i,153) = vb;
v(i,160) = vb;
end
for j=153:160 %set potential at certain coordinate
v(13,j) = vb;
v(20,j) = vb;
end
for k=1:ni %no iteration
for i=2:nx-1 %x loop
for j=2:ny-1 %y loop
v(i,j) = (1/4)*( v(i+1,j) + v(i-1,j) + v(i,j+1) + v(i,j-1) );
display(v(i,j));
end
end
end
X = (1:1:200);
Y = (1:1:200);
figure(1);
contour (X,Y,v);

You might also like