MATLAB Model a circle using finite difference equation in matlab

  • Thread starter tomallan
  • Start date
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.
 
137
5
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.
 
105
4
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?
 

Related Threads for: Model a circle using finite difference equation in matlab

Replies
28
Views
79K
Replies
0
Views
8K
Replies
1
Views
4K
Replies
3
Views
2K
Replies
1
Views
785
Replies
1
Views
8K
Replies
0
Views
14K

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top