【发布时间】:2021-12-29 08:30:17
【问题描述】:
我尝试通过修复平行板电容器代码来解决以下二维椭圆 PDE 静电问题。但是我在绘制圆形区域时遇到问题。如何绘制圆形区域而不是正方形?
% I use following two lines to label the 50V and 100V squares
% (but it should be two circles)
V(pp1-r_circle_small:pp1+r_circle_small,pp1-r_circle_small:pp1+r_circle_small) = 50;
V(pp2-r_circle_big:pp2+r_circle_big,pp2-r_circle_big:pp2+r_circle_big) = 100;
% Contour Display for electric potential
figure(1)
contour_range_V = -101:0.5:101;
contour(x,y,V,contour_range_V,'linewidth',0.5);
axis([min(x) max(x) min(y) max(y)]);
colorbar('location','eastoutside','fontsize',10);
xlabel('x-axis in meters','fontsize',10);
ylabel('y-axis in meters','fontsize',10);
title('Electric Potential distribution, V(x,y) in volts','fontsize',14);
h1=gca;
set(h1,'fontsize',10);
fh1 = figure(1);
set(fh1, 'color', 'white')
% Contour Display for electric field
figure(2)
contour_range_E = -20:0.05:20;
contour(x,y,E,contour_range_E,'linewidth',0.5);
axis([min(x) max(x) min(y) max(y)]);
colorbar('location','eastoutside','fontsize',10);
xlabel('x-axis in meters','fontsize',10);
ylabel('y-axis in meters','fontsize',10);
title('Electric field distribution, E (x,y) in V/m','fontsize',14);
h2=gca;
set(h2,'fontsize',10);
fh2 = figure(2);
set(fh2, 'color', 'white')
【问题讨论】:
-
您好,欢迎来到 Stack Overflow!请阅读How to Ask,然后阅读edit 您的问题,以将每个帖子的问题数量限制为 1。此规则的存在是因为它使 Stack Overflow 可作为知识数据库进行搜索,而不仅仅是服务台的目的。所以请删除你的第二个问题,你能把你的代码减少到minimal reproducible example吗?最小的部分是相关的,请突出显示您在代码中绘制正方形的位置并删除所有不相关的代码。这让我们更容易为您提供帮助。
-
重读您的第二个问题后:这与 Stack Overflow 无关。这不是编程问题,而是电气工程问题(或您对结果的解释中的问题)。尝试我们网络上专门用于电气工程的任何姊妹站点,以找到该问题的答案。虽然第一个问题是有效的,但请说明您在代码中绘制正方形的位置以及您希望如何将其更改为圆形。
-
好的!对此感到抱歉。我马上修改。
-
对,所以你基本上是用方形索引索引你的
V,这会给你一个正方形。相反,您需要定义圆内的点(提示:您有中心和半径,任何网格点上的简单sqrt((x-x0)^2+(y-y0)^2)都会告诉您它是在里面还是在外面)并且只将这些值设置为50 或 100。剩下的代码你可以留下来,我一眼就能看出