There is a long direct metal rectangular slot, length a=40, width b=20, the potential of the side wall and bottom surface are zero, the potential of the top cover is 100V (relative value), and the potential distribution in the slot is obtained.
The solution code using Gaussian iteration is as follows (the maximum allowable error of two adjacent iteration values is 0.001):
a=zeros(21,41); a(1,:)=100; b=zeros(19,39); c=eye(19,39); count=1; d=0; while(count==1) m=0; for i=2:1:20 for j=2:1:40 b(i-1,j-1)=a(i,j); a(i,j)=0.25*(a(i-1,j)+a(i+1,j)+a(i,j-1)+a(i,j+1)); c(i-1,j-1)=abs(a(i,j)-b(i-1,j-1)); if(c(i-1,j-1)<0.001) for k=1:1:19 for n=1:1:39 if(c(k,n)<0.00001) m=m+1; else m=0; break; end end if(m==0) break; end if(m==741) count=0; end end end if(count==0) break; end end if(count==0) break; end end d=d+1; end d a
The procedure for using the over-relaxation method is as follows:
d=zeros(1,10); h=0; for e=1:0.1:1.9 a=zeros(21,41); a(1,:)=100; b=zeros(19,39); c=eye(19,39); count=1; g=0; while(count==1) m=0; for i=2:1:20 for j=2:1:40 b(i-1,j-1)=a(i,j); a(i,j)=a(i,j)+e*0.25*(a(i-1,j)+a(i+1,j)+a(i,j-1)+a(i,j+1)-4*a(i,j)); c(i-1,j-1)=abs(a(i,j)-b(i-1,j-1)); if(c(i-1,j-1)<0.001) for k=1:1:19 for n=1:1:39 if(c(k,n)<0.001) m=m+1; else m=0; break; end end if(m==0) break; end if(m==741) count=0; end end end if(count==0) break; end end if(count==0) break; end end g=g+1; end h=h+1; e d(1,h)=g; end d
If you find it useful, please like it~ If you have any questions, you can leave a message below, and I will try my best to reply~