MATLAB discretization of a 2D circular surface

In summary, the conversation discussed using the Charge/Coulombian model to model the magnetic force between two cylindrical identical sized permanent magnets. The person is doing these calculations in MATLAB and is looking for a more efficient way to discretize the magnet surfaces. They are considering using a circular surface area and dividing it into equal sized square facets. A potential solution was suggested using a square lattice of points and an if statement to create a logical mask indicating whether each point is inside or outside the circle. The person was also reminded to not post in bold letters as it is difficult to read.
  • #1
debwaldy
38
0
1. Hi,

I am trying to model the magnetic force between two cylindrical identical sized permanent magnets. I am using the Charge/Coulombian model to do this. This assumes that all of the "magnetic charge" is on the pole ends of the magnet, i.e. the flat surfaces at the top and bottom of each cylinder.

I am doing these calculations in MATLAB. I have managed to write code which produces a graph of force on one magnet, say M1 due to a second magnet, say M2, but this code is cumbersome and very slow so I need to find a more efficient way of discretizing the magnet surfaces.

At the moment I am dividing these circular surfaces into equal sized uniform square facets. Then I iterate along the X and Y axis, which is what is slowing me down, to get the central positioni of each facet, but this gives me some facets which are not inside the circular surfaces, so I am using an if statement and pythagoras to determine whether my point lies in my circle or is merely on the square which surrounds my circle.

This is all very slow so what I was goin to try and do was somehow use the radius of the circle to plot a circular surface area, and then divide this circle into the eqqual sized square facets as before. However I don't know how to read in this circular surface area so that I will have a 2D array which contains every single facet point - I am new to MATLAB

Any help or ideas would be much appreciated

Thank you
 
Physics news on Phys.org
  • #2
One quick way is to create a square lattice of points with meshgrid, then use a simple if statement to get a logical mask that indicates whether each point is inside or outside the circle.

Example, where a = radius of circle and npts = # of squares you want to put across the diameter.

xvec = linspace(-a,a,npts);
[x,y] = meshgrid(xvec,xvec);
mask = x.^2 + y.^2 <= a^2 * ones(npts,npts);
% Mask has logical 1's for points inside the circle

% If you plot x,y, you'll see that all points outside the circle are masked out.

plot(x(mask),y(mask),'.')
axis('square')

BTW, please it's better not to post in bold letters. They are hard to read.
 

Related to MATLAB discretization of a 2D circular surface

What is MATLAB discretization of a 2D circular surface?

MATLAB discretization of a 2D circular surface refers to the process of dividing a continuous 2D circular surface into smaller, discrete elements in order to perform calculations or simulations using MATLAB software.

How is a 2D circular surface discretized in MATLAB?

In MATLAB, a 2D circular surface can be discretized using the "meshgrid" function, which creates a grid of points on the surface. These points can then be used to define the boundaries of smaller elements on the surface.

What are the benefits of discretizing a 2D circular surface in MATLAB?

Discretizing a 2D circular surface in MATLAB allows for more efficient and accurate calculations and simulations. It also allows for easier visualization of the surface and its elements.

What factors should be considered when discretizing a 2D circular surface in MATLAB?

The number of points to use in the discretization, the size and shape of the elements, and the specific requirements of the simulation or calculation being performed should all be considered when discretizing a 2D circular surface in MATLAB.

Are there any limitations to discretizing a 2D circular surface in MATLAB?

The main limitation of discretizing a 2D circular surface in MATLAB is that it may not accurately represent the true continuous surface. This can be mitigated by using a smaller element size and a higher number of points in the discretization.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
874
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Replies
8
Views
1K
Replies
2
Views
759
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
2K
Replies
5
Views
2K
  • Electromagnetism
Replies
4
Views
1K
Back
Top