实验一:静电场的分析与求解1.求二维标量场u(r)=y^2-x的梯度[x,y]=meshgrid(-2:.2:2,-2:.2:2);z=y.^2-x;[px,py]=gradient(z,.2,.2);contour(z)holdonquiver(px,py)holdofftitle('等值线与梯度');2.2个等量同号点电荷组成的点电荷系的电势分布图clearv='1./((x-3).^2+y.^2).^0.5+1./((x+3).^2+y.^2).^0.5';xmax=10;ymax=10;ngrid=30;xplot=linspace(-xmax,xmax,ngrid);[x,y]=meshgrid(xplot);vplot=eval(v);[explot,eyplot]=gradient(-vplot);clf;subplot(1,2,1),meshc(vplot);xlabel('x');ylabel('y');zlabel('电位');subplot(1,2,2),axis([-xmaxxmax-ymaxymax]);cs=contour(x,y,vplot);clabel(cs);holdonquiver(x,y,explot,eyplot)xlabel('x');ylabel('y');holdoff3.电偶极子的场(等位线和梯度)clear;clf;q=2e-6;k=9e9;a=1.5;b=-1.5;x=-6:0.6:6;y=x;[X,Y]=meshgrid(x,y);rp=sqrt((X-a).^2+(Y-b).^2);rm=sqrt((X+a).^2+(Y+b).^2);V=q*k*(1./rp-1./rm);[Ex,Ey]=gradient(-V);AE=sqrt(Ex.^2+Ey.^2);Ex=Ex./AE;Ey=Ey./AE;cv=linspace(min(min(V)),max(max(V)),49);contourf(X,Y,V,cv,'k-')title('电偶极子的场'),holdonquiver(X,Y,Ex,Ey,0.7)plot(a,b,'wo',a,b,'w+')plot(-a,-b,'wo',-a,-b,'w-')xlabel('x');ylabel('y');holdoff实验二:磁感应强度求解1.单匝环形通电线圈形成的磁感应强度clearrh=2.5;i0=10;mu0=4*pi*1e-7;n=11m=(n+1)/2xmax=6;ymax=6;ngrid=40;cx(1:ngrid,1:ngrid)=zeros;cy(1:ngrid,1:ngrid)=zeros;c0=mu0/4*pi;nh=20;ngrid1=nh+1;xmax1=0;ymax1=2*pi;xplot=linspace(-xmax,ymax,ngrid);yplot=linspace(-xmax,ymax,ngrid);theta0=linspace(0.2*pi,21);theta1=theta0(1:nh);y1=rh*cos(theta1);z1=rh*sin(theta1);theta2=theta0(2:nh+1);y2=rh*cos(theta2);z2=rh*sin(theta2);dlx=0;dly=y2-y1;dlz=z2-z1;xc=[-(n-1)/2:2:(n-1)/2];yc=(y2+y1)/2;zc=(z2+z1)/2;fork=1:mfori=1:ngridforj=1:ngridrx=xplot(j)-xc(k);ry=yplot(i)-yc;rz=0-zc;r3=sqrt(rx.^2+ry.^2+rz.^2).^3;dlxr_x=dly.*rz-dlz.*ry;dlxr_y=dlz.*rx-dlx.*rz;bx(i,j)=sum(c0*i0*dlxr_x./r3);by(i,j)=sum(c0*i0*dlxr_y./r3);endendcx(1:ngrid,1:ngrid)=cx(1:ngrid,1:ngrid)+bx(1:ngrid,1:ngrid);cy(1:ngrid,1:ngrid)=cy(1:ngrid,1:ngrid)+by(1:ngrid,1:ngrid);endquiver(xplot,yplot,cx,cy);holdonplot(xc,rh,'r*')holdonplot(xc,-rh,'r*')n=11m=6实验三:时变电磁场电磁波的传播1.时变电磁场电磁波的传播