电磁场-点电荷-电场线-电势-MATLAB--仿真-中南大学 下载本文

内容发布更新时间 : 2024/11/2 19:31:23星期一 下面是文章的全部内容请认真阅读。

0.050.040.030.020.01一对不相等的电荷的等势线图和电场线图0-0.01-0.02-0.03-0.04-0.05-0.05y-0.04-0.03-0.02-0.0100.010.020.030.040.05x图4

点电荷电场分布的3-D图

1050-52-10201.510.50-0.5-1-1.5-2-2图5

部分M-file;

1. 点电荷的平面电力线和等势线 %点电荷的平面电力线和等势线 %平面电力线的画法 q=1e-9; r0=0.12;

th=linspace(0,2*pi,13); [x,y]=pol2cart(th,r0); x=[x;0.1*x]; y=[y;0.1*y]; plot(x,y); grid on hold on

plot(0,0,'o','MarkerSize',12) xlabel('x','fontsize',16) ylabel('y','fontsize',16)

2. 一对电荷平面等势线和电场线图%一对电荷平面等势线和电场线图

clear all; clf;

%平面等势线的画法 q1=2e-9; q2=-1e-9;

a=0.02;%到原点的距离 xx0=0.05; yy0=0.04; k=9e9;

x=linspace(-xx0,xx0,20); y=linspace(-yy0,yy0,50); [X,Y]=meshgrid(x);

r11=sqrt((xx0/1.7-a)^2+(yy0/1.7)^2);

r22=sqrt((xx0/1.7+a)^2+(yy0/1.7)^2);

r1=sqrt((X-a).^2+Y.^2); %各点到点电荷的距离 r2=sqrt((X+a).^2+Y.^2);

U=k*q1./r1+k*q2./r2;

title('单个点电荷的电场线与等势线','fontsize',20)

%平面等势线的画法 k=9e9; r0=0.1; u0=k*q/r0;

u=linspace(1,3,7)*u0; x=linspace(-r0,r0,100); [X,Y]=meshgrid(x); r=sqrt(X.^2+Y.^2); U=k*q./r; hold on;

contour(X,Y,U,u)

%各点的电势

u0=k*q1/r11+k*q2/r22;

u=linspace(u0,-u0,11); %取21个等势向量

contour(X,Y,U,u,'k-'); hold on grid on

plot(a,0,'o','MarkerSize',12); plot(-a,0,'o','MarkerSize',12); xlabel('x','fontsize',16); ylabel('y','fontsize',16);

%平面电力线的画法 [Ex,Ey]=gradient(-U); E=sqrt(Ex.^2+Ey.^2); Ex=Ex./E; Ey=Ey./E; hold on;

quiver(X,Y,Ex,Ey);

title('一对不相等的电荷的等势线图和电场线图','fontsize',20) clear;

3. 立体电力线的画法

%立体电力线的画法 q=1e-9;

[X,Y,Z]=sphere(8); r0=0.18; r1=0.2; k=9e9; u0=k*q/r0; x=r1*X(:)'; y=r1*Y(:)'; z=r1*Z(:)';

x=[x;zeros(size(x))]; y=[y;zeros(size(y))]; z=[z;zeros(size(z))]; plot3(x,y,z) hold on;

%立体等势线之画法

u=linspace(1,3,5)*u0; %画5 条等势面时, 各面的电势为u=linspace(1,3,5)+u0,

r=k*q./u; 4.

clear all; clf; q1=1; q2=1; a=0.02; xx0=0.05; yy0=0.04; k=9e9;

x=linspace(-xx0,xx0,20); y=linspace(-yy0,yy0,50); [X,Y]=meshgrid(x);

r11=sqrt((xx0/1.7-a)^2+(yy0/1.7)^2);

r22=sqrt((xx0/1.7+a)^2+(yy0/1.7)^2);

%各等势面的半径为r=k6q. /u [X,Y,Z]=sphere; Z(X<0&Y<0)=nan;

surf(r(1)*X,r(1)*Y,r(1)*Z); %第一到第五个球面 surf(r(2)*X,r(2)*Y,r(2)*Z); surf(r(3)*X,r(3)*Y,r(3)*Z); surf(r(4)*X,r(4)*Y,r(4)*Z); surf(r(5)*X,r(5)*Y,r(5)*Z);

shading interp %个颜色浓淡连续变化的命令shading interp.

xlabel('x','fontsize',16); ylabel('y','fontsize',16); zlabel('z','fontsize',16);

title('正电荷电场线等势面的三维图形','fontsize',20); clear;

r1=sqrt((X-a).^2+Y.^2); r2=sqrt((X+a).^2+Y.^2); U=k*q1./r1+k*q2./r2; u0=k*q1/r11+k*q2/r22; u=linspace(u0,-u0,11); contour(X,Y,U,u,'k-'); hold on

[Ex,Ey]=gradient(-U); E=sqrt(Ex.^2+Ey.^2); Ex=Ex./E; Ey=Ey./E; dth1=20;

th1=(dth1:dth1:180-dth1)*pi/180; r0=a/5;

x1=r0*cos(th1)+a; y1=r0*sin(th1);

streamline(X,Y,Ex,Ey,x1,y1); streamline(-X,-Y,-Ex,-Ey,x1,-y1); q=abs(q1/q2); dth2=dth1/q;

th2=(180-dth2:-dth2:dth2)*pi/180; x2=r0*cos(th2)-a; y2=r0*sin(th2);

streamline(X,Y,Ex,Ey,x2,y2); streamline(X,-Y,Ex,-Ey,x2,-y2); grid on

plot(a,0,'o','MarkerSize',12); plot(-a,0,'o','MarkerSize',12); xlabel('x','fontsize',16); ylabel('y','fontsize',16);

title('一对点电荷的电场分布图'); clear;

clear all; clf; q1=1; q2=1; a=0.02; xx0=0.05; yy0=0.04; k=9e9;

x=linspace(-xx0,xx0,20); y=linspace(-yy0,yy0,50); [X,Y]=meshgrid(x);

r11=sqrt((xx0/1.7-a)^2+(yy0/1.7)^2);

r22=sqrt((xx0/1.7+a)^2+(yy0/1.7)^ 5.

2);

r1=sqrt((X-a).^2+Y.^2); r2=sqrt((X+a).^2+Y.^2); U=k*q1./r1+k*q2./r2; u0=k*q1/r11+k*q2/r22; u=linspace(u0,-u0,11); contour(X,Y,U,u,'k-'); hold on

[Ex,Ey]=gradient(-U); E=sqrt(Ex.^2+Ey.^2); Ex=Ex./E; Ey=Ey./E; dth1=20;

th1=(dth1:dth1:180-dth1)*pi/180; r0=a/5;

x1=r0*cos(th1)+a; y1=r0*sin(th1);

streamline(X,Y,Ex,Ey,x1,y1); streamline(-X,-Y,-Ex,-Ey,x1,-y1); q=abs(q1/q2); dth2=dth1/q;

th2=(180-dth2:-dth2:dth2)*pi/180; x2=r0*cos(th2)-a; y2=r0*sin(th2);

streamline(X,Y,Ex,Ey,x2,y2); streamline(X,-Y,Ex,-Ey,x2,-y2); grid on

plot(a,0,'o','MarkerSize',12); plot(-a,0,'o','MarkerSize',12); xlabel('x','fontsize',16); ylabel('y','fontsize',16);

title('一对点电荷的电场分布图'); clear;

[x,y]=meshgrid(-2:0.1:2,-2:0.1:2);%建立数据网格

z=1./sqrt(x.^2+(y-1).^2+0.01)-1./sqrt(x.^2+(y+1).^2+0.01);%电势的表达式 surfl(x,y,z);%三维曲面绘图 shading interp %平滑i维曲面 title('点电荷电场分布的3-D图')