0% found this document useful (0 votes)
41 views1 page

Code Using Script in MATLAB

This MATLAB script simulates potential values on a grid over multiple iterations. It initializes the potential grid to zero, sets potential values of 80000 at certain coordinates to simulate objects, sets values of 160000 at other coordinates, then runs an iteration where the potential at each interior point is calculated as the average of its neighbors. Finally, it generates a contour plot of the final potential values.

Uploaded by

Wong Yinwen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views1 page

Code Using Script in MATLAB

This MATLAB script simulates potential values on a grid over multiple iterations. It initializes the potential grid to zero, sets potential values of 80000 at certain coordinates to simulate objects, sets values of 160000 at other coordinates, then runs an iteration where the potential at each interior point is calculated as the average of its neighbors. Finally, it generates a contour plot of the final potential values.

Uploaded by

Wong Yinwen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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