资源描述:
《matlab实现有限差分法计算电场强度(最新).doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、..实验一:有限差分法研究静电场边值问题实验报告人:年级和班级:学号:1.实验用软件工具:Matlab2.实验原理:电磁场课本P36-381)差分方程2)差分方程组的解简单迭代法高斯-赛德尔迭代法逐次超松弛法3.实验步骤:1)简单迭代法程序:hx=41;hy=21;v1=zeros(hy,hx);v1(hy,:)=zeros(1,hx);v1(1,:)=ones(1,hx)*100;v1(:,1)=zeros(hy,1);v1(:,hx)=zeros(hy,1);v1v2=v1;maxt=1;t=0;k=0;while(maxt>1e-5)k=k+1;ma
2、xt=0;fori=2:hy-1forj=2:hx-1v2(i,j)=(v1(i,j+1)+v1(i+1,j)+v1(i-1,j)+v1(i,j-1))/4;t=abs(v2(i,j)-v1(i,j));if(t>maxt)maxt=t;endendendv1=v2;endv2kclfsubplot(1,2,1),mesh(v2)axis([0,41,0,21,0,100])subplot(1,2,2),contour(v2,15)holdon.下载可编辑...axis([-1,42,-1,25])plot([1,1,hx,hx,1],[1,hy+1,hy
3、+1,1,1],'r')text(hx/2,0.3,'0V','fontsize',11);text(hx/2-0.5,hy+0.5,'100V','fontsize',11);text(-0.5,hy/2,'0V','fontsize',11);text(hx+0.3,hy/2,'0V','fontsize',11);holdoff当W=1e-5,迭代次数:1401次2)高斯-赛德尔迭代法程序:hx=41;hy=21;v1=ones(hy,hx);v1(hy,:)=zeros(1,hx);v1(1,:)=ones(1,hx)*100;v1(:,1)=ze
4、ros(hy,1);v1(:,hx)=zeros(hy,1);v2=v1;maxt=1;t=0;k=0;while(maxt>1e-5)k=k+1;maxt=0;fori=2:hy-1forj=2:hx-1v2(i,j)=(v1(i,j+1)+v1(i+1,j)+v2(i-1,j)+v2(i,j-1))/4;t=abs(v2(i,j)-v1(i,j));if(t>maxt)maxt=t;endendendv1=v2;endv2kclfsubplot(1,2,1),mesh(v2)axis([0,41,0,21,0,100])subplot(1,2,2),c
5、ontour(v2,15)holdonaxis([-1,42,-1,25])plot([1,1,hx,hx,1],[1,hy+1,hy+1,1,1],'r')text(hx/2,0.3,'0V','fontsize',11);text(hx/2-0.5,hy+0.5,'100V','fontsize',11);text(-0.5,hy/2,'0V','fontsize',11);text(hx+0.3,hy/2,'0V','fontsize',11);holdoff.下载可编辑...当W=1e-5,迭代次数:740次3)逐次超松弛法程序:hx=41;hy=
6、21;v1=zeros(hy,hx);v1(hy,:)=zeros(1,hx);v1(1,:)=ones(1,hx)*100;v1(:,1)=zeros(hy,1);v1(:,hx)=zeros(hy,1);v1v2=v1;maxt=1;t=0;alpha=input('pleaseinputthevalueofalpha(alpha>=1&&alpha<2):');k=0;while(maxt>1e-5)k=k+1;maxt=0;fori=2:hy-1forj=2:hx-1v2(i,j)=v1(i,j)+(v1(i,j+1)+v1(i+1,j)+v2(i
7、-1,j)+v2(i,j-1)-4*v1(i,j))*alpha/4;t=abs(v2(i,j)-v1(i,j));if(t>maxt)maxt=t;endendendv1=v2;endv2kclfsubplot(1,2,1),mesh(v2)axis([0,41,0,21,0,100])subplot(1,2,2),contour(v2,15)holdonaxis([-1,42,-1,25])plot([1,1,hx,hx,1],[1,hy+1,hy+1,1,1],'r')text(hx/2,0.3,'0V','fontsize',11);text(hx
8、/2-0.5,hy+0.5,'100V','fontsize',1