Model a circle using finite difference equation in matlab

In summary, the conversation involves a person struggling with code in MATLAB to model a distribution with a circular geometry. The code provided involves a flat step condition and uses variables nHi, nHj, and R_P to determine the maximum size of nodes in the X and Y directions and the radius of the circle. The person is looking for tips on how to make the graph appear as a circle when viewed from the top. A suggestion is made to use polar coordinates instead.
  • #1
tomallan
20
0
hello. I have a MATLAB skeleton provided because i want to model a distribution with a circular geometry. all in all, i want the 3d graph of the code to be some type of cylinder. This is the code:

% flat step condition
for ii=1:nHi,
for jj=1:nHj,
if (X(ii)/R_P)<1 & (Y(ii)/R_P)<1,
h(ii,jj)=h_init+h_step;
else,
h(ii,jj)=h_init;
end
end
end

nHi is the maximum size of nodes in X direction and nHj is the maximum size in Y direction while R_P is the radius of the circle. I am struggling with this code because when I execute this, it only appears with a rectangular graph, instead of a circle-ish, when viewed from the top.

what the code is trying to say is,
if node is less than the diameter (x or y node),
thickness is initial+step
else,
thickness is initial.

Any tips will be greatly appreciated.
 
Physics news on Phys.org
  • #2
Just a hunch, have you tried replacing this:

if (X(ii)/R_P)<1 & (Y(ii)/R_P)<1

with this?

if ((X(ii) - Xm)^2 + (Y(ii) - Ym)^2 < R_P^2)

where Xm and Ym are the coordinates of the center of the circle.
 
  • Like
Likes 1 person
  • #3
Are you trying to embed a circle to a square domain or are you trying to make a circle domain? Why not do it in polar coordinates?
 

1. How do I model a circle using finite difference equation in Matlab?

To model a circle using finite difference equation in Matlab, you can use the "circle" function. This function generates a set of x, y coordinates for a circle with a given radius. You can then plot these coordinates to create a circle.

2. What is a finite difference equation?

A finite difference equation is a mathematical equation that is used to approximate the derivative of a function. It involves using a finite number of points to approximate the derivative at a specific point.

3. Can I change the resolution of the circle model?

Yes, you can change the resolution of the circle model by adjusting the number of points used to generate the circle coordinates. The more points you use, the smoother the circle will appear.

4. How can I plot the circle using finite difference equation in Matlab?

To plot the circle using finite difference equation in Matlab, you can use the "plot" function. This function takes in the x and y coordinates generated by the "circle" function and plots them on a graph.

5. Are there any limitations to modeling a circle using finite difference equation in Matlab?

Yes, there are some limitations to modeling a circle using finite difference equation in Matlab. One limitation is that the circle may not appear perfectly smooth, especially if a low number of points are used. Additionally, the circle may not be a perfect circle if the radius is too large or too small.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
561
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
Back
Top