Finite difference method with matlab- square grid, cavity inside

Click For Summary
SUMMARY

The discussion focuses on implementing the finite difference method in MATLAB to calculate the electric field and potential within a square grid that contains a cavity. The user has set up the initial parameters, including grid dimensions and boundary conditions, but encounters challenges in restricting calculations within the cavity area. The solution involves modifying the code to ensure that potential values are not computed at the cavity nodes, which the user later resolves independently.

PREREQUISITES
  • Understanding of finite difference methods for numerical analysis
  • Familiarity with MATLAB programming and syntax
  • Knowledge of electric field and potential concepts in physics
  • Experience with grid-based simulations and boundary conditions
NEXT STEPS
  • Explore MATLAB's array manipulation techniques for grid-based calculations
  • Learn about implementing boundary conditions in numerical simulations
  • Research advanced finite difference methods for complex geometries
  • Study optimization techniques for improving simulation performance in MATLAB
USEFUL FOR

Students and professionals in physics, electrical engineering, and computational modeling who are working on simulations involving electric fields and potential distributions in grid-based systems.

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 ·
Replies
1
Views
4K
  • · Replies 41 ·
2
Replies
41
Views
10K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
1
Views
2K
Replies
5
Views
8K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K