Distribute data in the form of a circle
조회 수: 5 (최근 30일)
이전 댓글 표시
Hello!
How to create a 2D grid of data in following two cases?
Case 1: Input data (say "z1") is in such a way that z1 = pi at the center and it decays to z1 = 0 outwards (like a circle on the 2D grid).
Case 2: Input data (say "z2") with formula z2 = atan[(y-y0)/(x-x0)] + pi/2, in which (x0,y0) being the center of the square grid.
Note: The output 2D grid has to be used for further calculations.
Thanks in advance.
Nasir
댓글 수: 2
채택된 답변
John D'Errico
2021년 4월 1일
편집: John D'Errico
2021년 4월 1일
You say you want to distribute data, which implies you want to see random numbers, based on some vague, unspecified distribution. But really, it looks as if you just want to create several 2-dimensional surfaces?
In the first case, you talk about some function being pi at the center of your grid, and then it needs to "decay". But we don't know what shape the decay should follow. I suppose an exponential decay would be acceptable, but even then, we are not told how fast that should be! Consider these three profiles:
rate1 = 0.2;
rate2 = 0.025;
rate3 = 0.01;
radDecay = @(r,rate) pi*exp(-r*rate);
fplot(@(r) radDecay(r,rate1),[0,200])
hold on
fplot(@(r) radDecay(r,rate2),[0,200])
fplot(@(r) radDecay(r,rate3),[0,200])
legend('Fast decay','Slow decay','Really slow decay')
hold off
So they all start at pi at the center, and decay with different rates. Implement that as a surface simply enough. I'll use the intermediate decay rate here. As you can see, at a distance of 200 units from the center, the intermediate decay rate will be almost zero, though it will never truly get to exactly zero. That is what exponential decay means.
[X,Y] = meshgrid(-200:200);
[~,S1] = cart2pol(X,Y); S1 = radDecay(S1,rate2);
figure
H = surf(S1);
H.LineStyle = 'none';
So that shows the basic shape I've created. You can feel free to fine tune the rate to make it look as you wish. Larger values for the rate parameter will create a surface that decays more rapidly.
figure
H = pcolor(S1);
H.LineStyle = 'none';
Some other fundamental shape would be as easy to implement. That is your choice. The idea is to create the shape you want for the radial decay first. THEN implement it as a surface as I did. meshgrid and cart2pol will do all the work for you.
댓글 수: 2
John D'Errico
2021년 4월 1일
편집: John D'Errico
2021년 4월 1일
I fail to see the problem. Just pick some distance where that function becomes truly zero. WTP? So you might do it as:
zerobreak = 100;
radDecay = @(r,rate) pi*exp(-r*rate) .* (r<zerobreak);
fplot(@(r) radDecay(r,0.025),[0,200])
I've chosen a limit where the truncation is painfully obvious. But you can choose any set of constants you wish. And if you want it to be some other non-zero constant, it is also trivially easy.
Since your surfaces are always circularly symmetric, just design the shape in the radial direction you want as a 1-dimensional profile FIRST. This allows you to envision exactly the profile you want to see happen.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 General PDEs에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!