Plot vector field within given region (between two circles) in matlab

可紊 提交于 2019-12-06 09:08:24

Set up your radii, centre of circle and x,y variables like so

r1 = 5; r2 = 10;  % Radii of your circles
x_0 = 0; y_0 = 1; % Centre of circles
[x,y] = meshgrid(x_0-r2:0.2:x_0+r2,y_0-r2:0.2:y_0+r2); % meshgrid of points

Then get which points are within the annulus described by the two circles, do this by using the circle equations which define the region:

idx = ((x-x_0).^2 + (y-y_0).^2 > r1^2 & (x-x_0).^2 + (y-y_0).^2 < r2^2);

Define your vector field

u = cos(x-x_0).*y-y_0;
v = sin(x+x_0).*y+y_0;

Then plot the vector field of these points using quiver like you did:

quiver(x(idx),y(idx),u(idx),v(idx));

Output:


Edit:

If your vector field is complicated, you would save a lot of computation time by first removing elements from x and y which you are not interested in. After calculating idx, do:

x = x(idx);
y = y(idx);

Then calculate u and v and you can plot by simply calling quiver(x,y,u,v).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!