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

• MATLAB
• 10city
In summary, the person is trying to find an algorithm to find an electric field within a square grid mesh with a square cavity inside. They are stuck because they don't know how to proceed.
10city
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.

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'];

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?

regards

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

## 1. What is the finite difference method (FDM)?

The finite difference method is a numerical technique used to approximate the solutions of differential equations. It involves discretizing the domain into a grid and calculating the values of the unknown function at discrete points on the grid using finite difference approximations of the derivatives.

## 2. How is the square grid used in the FDM with Matlab?

The square grid is a type of structured grid where the grid points are arranged in a regular, rectangular pattern. In the FDM with Matlab, this grid is used to discretize the domain and solve for the values of the unknown function at each grid point.

## 3. What is a cavity and how does it affect the FDM solution?

A cavity is an enclosed space or region within the domain. In the FDM with Matlab, a cavity inside the domain can create boundary conditions that need to be considered in the solution. The shape and size of the cavity can also affect the accuracy and stability of the FDM solution.

## 4. What are the advantages of using Matlab for FDM?

Matlab is a powerful numerical computing software that offers built-in functions for solving differential equations and visualizing results. It also has a user-friendly interface and programming language, making it easier to implement and troubleshoot FDM solutions.

## 5. What are some common challenges when using FDM with Matlab for a cavity problem?

Some common challenges when using FDM with Matlab for a cavity problem include choosing an appropriate grid size and boundary conditions, handling the non-linearity or complexity of the problem, and ensuring the stability and accuracy of the solution. It is also important to consider the convergence of the solution and to validate the results against analytical or experimental data.

Replies
1
Views
1K
Replies
1
Views
4K
Replies
41
Views
9K
Replies
4
Views
2K
Replies
1
Views
1K
Replies
5
Views
7K
Replies
3
Views
3K
Replies
1
Views
3K
Replies
2
Views
2K
Replies
1
Views
4K