基于Matlab的电磁场与波“电轴法”仿真

0、代码中用到的drawEline函数

在使用代码前记得把这个函数和仿真文件放到一个文件夹下哦

function pipi=drawEline(h1,d1,d2)
 
posAxes = get(gca, 'Position');  %获取当前坐标区位置信息
posX = posAxes(1);
posY = posAxes(2);
width = posAxes(3);
height = posAxes(4);%分解位置信息
hold on;
limX = get(gca, 'Xlim');%获取x轴范围
limY = get(gca, 'Ylim');%获取y轴范围
minX = limX(1);
maxX = limX(2);
minY = limY(1);
maxY = limY(2);
x=[h1(1).XData(d1) h1(1).XData(d2)];
y=[h1(1).YData(d1) h1(1).YData(d2)];
xNew = posX + (x - minX) / (maxX - minX) * width;
yNew = posY + (y - minY) / (maxY - minY) * height;%通过坐标变换得到箭头的绝对坐标
pipi=annotation('arrow', xNew, yNew);

1.目的:

  了解电轴法的等效原理,学会用MATLAB绘制电轴法的电场线与等势面。

2.理论分析:

 

3.源代码与结果

3.1两根相同半径轴线(电压已知,tao未知):

3.1.1二维图源代码:

a = 3;b = 4;d = 5;u0 = 10;
e0 = 10^(-9)/(36*pi);
x = linspace(-10,10,500);
y = linspace(-10,10,500);
theta=linspace(0,2*pi,50);
xr1=b+a*cos(theta);
yr1=a*sin(theta);
xr2=-b+a*cos(theta);
yr2=a*sin(theta);
[xx, yy]=meshgrid(x, y);
tao = pi*e0*u0/(log((b+d-a)/(b-d+a)));
fai = tao*log(sqrt((xx-b).^2+yy.^2)./sqrt((xx+b).^2+yy.^2))/(2*pi*e0);
[Ex,Ey] = gradient(fai);
E = sqrt(Ex.^2+Ey.^2);
Ex = Ex./E;Ey = Ey./E;
cv=linspace(min(min(fai)),max(max(fai)),51);
contour(xx,yy,fai,cv,'r-');
title('\fontname{ ËÎÌå }\fontsize{11} 两半径相同电轴'),hold on
plot(xr1,yr1,'k','linewidth',2)
plot(xr2,yr2,'k','linewidth',2)
xlabel('x');ylabel('y'),hold off
th=linspace(0,2*pi,17);
x1=-b+0.01*cos(th);
y1=0.01*sin(th);
x2=b+0.01*cos(th);
y2=0.01*sin(th);
for i=1:17
    h1=streamline(xx,yy,-Ex,-Ey,x1(i),y1(i));  
        switch i
            case {1,2,9,16}
                drawEline(h1,1000,1001);
            case {3,15}
                drawEline(h1,1030,1031);
            case {4,14}
                drawEline(h1,1150,1151);
            case {5,13}
                drawEline(h1,1350,1351);                
            case {6,12}
                drawEline(h1,1650,1651);
            case {7,11}
                drawEline(h1,2700,2701);
            case {8,10}
                drawEline(h1,930,931);
            otherwise
                continue
        end
end
for i=[1,2,16]
    h1=streamline(xx,yy,Ex,Ey,x2(i),y2(i)); 
    switch i
        case {2,16}
            drawEline(h1,930,929);
        case 1
            drawEline(h1,1000,999);
        otherwise
            continue
    end
end


fill(xr2,yr2,'w')
fill(xr1,yr1,'w')
for i=1:17
    h1=streamline(xx,yy,-Ex,-Ey,x1(i),y1(i));  
        set(h1,'linestyle','--');
        switch i
            case {1,2,9,16}
                drawEline(h1,1000,1001);
            case {3,15}
                drawEline(h1,1030,1031);
            case {4,14}
                drawEline(h1,1150,1151);
            case {5,13}
                drawEline(h1,1350,1351);                
            case {6,12}
                drawEline(h1,1650,1651);
            case {7,11}
                drawEline(h1,2700,2701);
            case {8,10}
                drawEline(h1,930,931);
            otherwise
                continue
        end
end
for i=[1,2,16]
    h1=streamline(xx,yy,Ex,Ey,x2(i),y2(i)); 
    set(h1,'linestyle','--');
    switch i
        case {2,16}
            drawEline(h1,930,929);
        case 1
            drawEline(h1,1000,999);
        otherwise
            continue
    end
end

3.1.2二维图结果:

修改前

 修改后

 3.1.3三维图源代码:

x = linspace(-10,10,500);
y = linspace(-10,10,500);
[xx, yy]=meshgrid(x, y);
a = 3;b = 4;d = 5;u0 = 10;
e0 = 10^(-9)/(36*pi);
tao = pi*e0*u0/(log((b+d-a)/(b-d+a)));
fai = tao*log(sqrt((xx-b).^2+yy.^2)./sqrt((xx+b).^2+yy.^2))/(2*pi*e0);
[Ex,Ey] = gradient(fai);
E = sqrt(Ex.^2+Ey.^2);
Ex = Ex./E;Ey = Ey./E;
fai0 = tao*log(0.1/7.9)/(2*pi*e0);
F = linspace(-fai0,fai0,40);
surf(fai);
hold on
shading interp;

subplot(2,1,1);
[c,h]=contour3(fai,F);
h1=streamslice(Ex,Ey);
set(h1,'Color',[0.1 0.9 0.8]);

subplot(2,1,2);
for j=1:length(h1)
    ui = interp2(fai,h1(j).XData,h1(j).YData);
    h1(j).ZData = ui;
end
[c,h]=contour3(fai,F);
h.EdgeColor='k';
h.LineStyle='--';
colormap(white);

3.1.4三维图结果

修改前

 修改后

3.2两根半径不同轴线(非嵌套,tao已知):

3.2.1计算公式:

 由以下关系式

 可得

 3.2.2二维图源代码:

a1 = 2.5;a2 = 4;d = 7;tao=2.5484e-10;
h1=(d^2+a1^2-a2^2)/(2*d);
h2=(d^2-a1^2+a2^2)/(2*d);
b=sqrt(h1^2-a1^2);
e0 = 10^(-9)/(36*pi);
x = linspace(-10,10,500);
y = linspace(-10,10,500);
theta=linspace(0,2*pi,50);
xr1=h2+a2*cos(theta);
yr1=a2*sin(theta);
xr2=-h1+a1*cos(theta);
yr2=a1*sin(theta);
[xx, yy]=meshgrid(x, y);
fai = tao*log(sqrt((xx-b).^2+yy.^2)./sqrt((xx+b).^2+yy.^2))/(2*pi*e0);
[Ex,Ey] = gradient(fai);
E = sqrt(Ex.^2+Ey.^2);
Ex = Ex./E;Ey = Ey./E;
cv=linspace(min(min(fai)),max(max(fai)),51);
contour(xx,yy,fai,cv,'r-');
title('\fontname{ ËÎÌå }\fontsize{11} 两根半径不同轴线(非嵌套) '),hold on
plot(xr1,yr1,'k','linewidth',2)
plot(xr2,yr2,'k','linewidth',2)
xlabel('x');ylabel('y'),hold off
th=linspace(0,2*pi,51);
x1=-b+0.01*cos(th);
y1=0.01*sin(th);
x2=b+0.01*cos(th);
y2=0.01*sin(th);
for i=[1,5,9,13,17,21,22,23,29,30,31,35,39,43,47]
    h1=streamline(xx,yy,-Ex,-Ey,x1(i),y1(i)); 
        switch i
            case 1
                drawEline(h1,350,351);
            case {5,47}
                drawEline(h1,360,361);
            case {9,43}
                drawEline(h1,388,389);                
            case {13,39}
                drawEline(h1,445,446);
            case {17,35}
                drawEline(h1,530,531);
            case {21,31}
                drawEline(h1,940,941);    
            case {22,30}
                drawEline(h1,1270,1271);
            case {23,29}
                drawEline(h1,1930,1931);
            otherwise
                continue
        end
end
 
for i=[24,25,26,27,28]
    h1=streamline(xx,yy,-Ex,-Ey,x1(i),y1(i));
    drawEline(h1,1250,1251); 
end
 
for i=[1,2,3,50,49]
    h1=streamline(xx,yy,Ex,Ey,x2(i),y2(i));
    drawEline(h1,1250,1249); 
end

3.2.3二维图结果:

(实在肝不动了,就不抠细节了)

 3.2.4三维图源代码:

a1 = 2.5;a2 = 4;d = 7;tao=2.5484e-10;
h1=(d^2+a1^2-a2^2)/(2*d);
h2=(d^2-a1^2+a2^2)/(2*d);
b=sqrt(h1^2-a1^2);
e0 = 10^(-9)/(36*pi);
x = linspace(-10,10,500);
y = linspace(-10,10,500);
[xx, yy]=meshgrid(x, y);
fai = tao*log(sqrt((xx-b).^2+yy.^2)./sqrt((xx+b).^2+yy.^2))/(2*pi*e0);
fai0 = tao*log(0.05/2.4878)/(2*pi*e0);
F = linspace(-fai0,fai0,60);
[Ex,Ey] = gradient(fai);
E = sqrt(Ex.^2+Ey.^2);
Ex = Ex./E;Ey = Ey./E;
surf(fai);
hold on
shading interp;
h1=streamslice(Ex,Ey);
set(h1,'Color',[0.1 0.9 0.8]);
for j=1:length(h1)
    ui = interp2(fai,h1(j).XData,h1(j).YData);
    h1(j).ZData = ui;
end
[c,h]=contour3(fai,F);
h.EdgeColor='k';
h.LineStyle='--';
colormap(jet);

3.2.5三维图结果:

3.3两根半径相同轴线(嵌套,tao已知):

3.3.1计算公式:

 由以下关系式

可得

 3.3.2二维图源代码

a1 = 1.5;a2 = 4;d = 2;tao=2.5484e-10;
H1=(a2^2-a1^2-d^2)/(2*d);
H2=(a2^2-a1^2+d^2)/(2*d);
b=sqrt(H1^2-a1^2);
e0 = 10^(-9)/(36*pi);
x = linspace(-10,10,500);
y = linspace(-10,10,500);
theta=linspace(0,2*pi,50);
xr1=-H2+a2*cos(theta);
yr1=a2*sin(theta);
xr2=-H1+a1*cos(theta);
yr2=a1*sin(theta);
[xx, yy]=meshgrid(x, y);
fai = tao*log(sqrt((xx-b).^2+yy.^2)./sqrt((xx+b).^2+yy.^2))/(2*pi*e0);
[Ex,Ey] = gradient(fai);
E = sqrt(Ex.^2+Ey.^2);
Ex = Ex./E;Ey = Ey./E;
cv=linspace(min(min(fai)),max(max(fai)),51);
contour(xx,yy,fai,cv,'r-');
title('\fontname{ ËÎÌå }\fontsize{11} 两根半径不同轴线(嵌套)'),hold on
plot(xr1,yr1,'k','linewidth',2)
plot(xr2,yr2,'k','linewidth',2)
xlabel('x');ylabel('y'),hold off
th=linspace(0,2*pi,51);
x1=-b+0.01*cos(th);
y1=0.01*sin(th);
x2=b+0.01*cos(th);
y2=0.01*sin(th);
for i=[1,5,9,13,17,21,22,23,29,30,31,35,39,43,47]
    h1=streamline(xx,yy,-Ex,-Ey,x1(i),y1(i)); 
        switch i
            case {1,5,47}
                drawEline(h1,550,551);
            case {9,43}
                drawEline(h1,570,571);                
            case {13,39}
                drawEline(h1,680,681);
            case {17,35}
                drawEline(h1,950,951);
            case {21,31}
                drawEline(h1,1950,1951);    
            case {22,30}
                drawEline(h1,2570,2571);
            case {23,29}
                drawEline(h1,1230,1231);
            otherwise
                continue
        end
end
 
for i=[24,25,26,27,28]
    h1=streamline(xx,yy,-Ex,-Ey,x1(i),y1(i));
    drawEline(h1,1250,1251); 
end
 
for i=[1,2,3,4,48,49,50]
    h1=streamline(xx,yy,Ex,Ey,x2(i),y2(i));
    drawEline(h1,1250,1249); 
end

3.3.3二维图结果

 3.3.4三维图源代码

a1 = 1.5;a2 = 4;d = 2;tao=2.5484e-10;
H1=(a2^2-a1^2-d^2)/(2*d);
H2=(a2^2-a1^2+d^2)/(2*d);
b=sqrt(H1^2-a1^2);
e0 = 10^(-9)/(36*pi);
x = linspace(-10,10,500);
y = linspace(-10,10,500);
[xx, yy]=meshgrid(x, y);
fai = tao*log(sqrt((xx-b).^2+yy.^2)./sqrt((xx+b).^2+yy.^2))/(2*pi*e0);
fai0 = tao*log(0.1/3.7426)/(2*pi*e0);
F = linspace(-fai0,fai0,60);
[Ex,Ey] = gradient(fai);
E = sqrt(Ex.^2+Ey.^2);
Ex = Ex./E;Ey = Ey./E;
surf(fai);
hold on
shading interp;
h1=streamslice(Ex,Ey);
set(h1,'Color',[0.1 0.9 0.8]);
for j=1:length(h1)
    ui = interp2(fai,h1(j).XData,h1(j).YData);
    h1(j).ZData = ui;
end
[c,h]=contour3(fai,F);
h.EdgeColor='k';
h.LineStyle='--';
colormap(jet);

3.3.5三维图结果

  • 12
    点赞
  • 58
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鸽呜顾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值