MATLAB Finite difference method with matlab- square grid, cavity inside

AI Thread Summary
The discussion centers on constructing a MATLAB program to calculate the electric field and potential within a square grid mesh that includes a square cavity. The user has set up initial parameters, including the number of grid points, mesh size, and fixed potential values. The program iterates through the grid to compute potential values and electric fields, but the user encounters a challenge in defining the cavity's boundaries to prevent calculations at those nodes. After some initial confusion, the user expresses a desire for guidance on how to implement the cavity restrictions effectively. The conversation highlights the importance of correctly managing boundary conditions in numerical simulations.
10city
Messages
2
Reaction score
0
Hi,

I'm here for help and hope somebody could give a hand on this because I'm noob in this.

I'm now constructing a MATLAB program to find Electrical field and potential within a square grid mesh with square cavity inside.
Picture0001.jpg

like the picture above.


I only manage up to this

v2=100.0;
%set no. of iteration
ni=1;
%nx=no. of x grid points
nx=8;
%ny=no. of y grid points
ny=6;
%set mesh size
d=5;
%nm=no of x grid for cavity
nm=4;
%nn=no of y grid for cavity
nn=3;
%set initial values equal to zeroes
v=zeros(nx+2,ny+2);
u=(nx-(nm-1));
t=(ny-(nm-1));

%fix potential at fixed nodes
for i=u:nx+1
v(i,t-1)=v2;
end
for j=t:ny+1
v(u-1,j)=v2;
end

head=['Iteration Coordinate Potential East North West South Electric field '
' Ex Ey'];

disp(head)

for k=1:ni
for u=2:nx+1
for t=2:ny+1
v(u,t)=0.25*(v(u,t)+v(u-1,t)+v(u,t+1)+v(u,t-1)+2*d^2);
Ex=(v(u+1,t)-v(u-1,t))/(2*d);
Ey=(v(i,u+1)-v(u,t-1))/(2*d);
fprintf('\t%5g \t(%g,%g) \t%5g \t%5g \t%5g \t%5g \t%5g \t%5g \t%5g \n ',k,u,t,v(u,t),v(u+1,t),v(u,t+1),v(u-1,t),v(u,t-1),Ex,Ey);
end
end
end



It seems that I'm now stuck where should i put a restriction to where the cavity is(that means, the program should not be calculating the V at that nodes)


can you give me some ideas how should i proceed with this?

thanks in advance.

regards
 
Physics news on Phys.org
it's okay. I already found the way to do it.
 
Bro, nice to meet you, can u teach me how to do this question?? i don't know how to do:(

Hope u can help me, thx
 

Similar threads

Replies
1
Views
4K
Replies
4
Views
3K
Replies
3
Views
4K
Replies
2
Views
2K
Replies
9
Views
3K
Back
Top