少了一个end,给改如下
- clear
- h=1;
- v0=100;
- hx=16;
- hy=10;
- v1=zeros(hy,hx);
- v1(hy,:)=ones(1,hx)*v0;
- v1(2:hy-1,2:hx-1)=ones(hy-2,hx-2)*v0/2;
- v2=zeros(hy,hx);
- for i=1:hy
- for j=1:hx
- if i==hy
- v2(i,j)=v0;
- elseif i==1|j==1|j==hx
- v2(i,j)=0;
- else
- v2(i,j)=[v1(i,j-1)+v1(i,j+1)+v1(i-1,j)+v1(i+1,j)]/4;
- end
- end
- end
- for k=1:500
- v1=v2;
- for i=1:hy
- for j=1:hx
- if i==hy
- v2(i,j)=0;
- elseif i==1|j==1|j==hx
- v2(i,j)=0;
- else
- v2(i,j)=[v1(i,j-1)+v1(i,j+1)+v1(i-1,j)+v1(i+1,j)]/4;
- end
- end
- end
- end
- subplot(1,2,1),mesh(v2)
- h1=mesh(v2);
- set(h1,'linewidth',1,'edgecolor','b')
- text(-6,10,120,'v','fontsize',10);
- text(-4,12,0,'h','fontsize',10);
- text(18,0,0,'b','fontsize',10);
- hold on
- axis([0 17 0 10 0 100]);
- subplot(1,2,2),
- contour(v2,'k-')
- text(-2,10,'h','fontsize',10);
- text(17,1,'b','fontsize',10);
- hold on
复制代码 |