clearclcw=1.8;n=111;m=33;hx= 4/32 ; %space betweem nodes in x direction
hy=20/110+1; h=hy/hx;E0=8.85*10^(-12); v_now= zeros(n,34);d=2:33;v_now(110,d)=100;v_now(105,14:21)=100;v_prev= zeros(n,34);v_now(:,34)=v_now(:,2);iter=0;[x y]=ndgrid(1:111,1:32);error=(sum(sum((abs(v_now-v_prev))/m*n)));while(error>0.01)%Run this until convergence
[x,y]= meshgrid(1:34,1:111) iter=iter+1; % Iteration counter increment
*for i=105 for j=2:12 E (i, j)= 8.85*10.^(-12); E (i-1,j)=8.85*10.^(-12); E (i-1, j-1)=8.85*10.^(-11); %%permittivity of interface region
E (i, j-1)=8.85*10.^(-11); a=(E (i, j)+E (i, j-1)); b=(E (i-1,j)+E (i-1, j-1)); c= E (i, j)+E (i-1, j); d=E (i, j-1)+E (i-1, j-1); W1 (i, j)=(h.^2).*a; W2 (i, j)=(h.^2).*b; W3 (i, j)=c; W4 (i, j)=d; W (i, j)=a+b+c+d; v_now (i, j)= (1-w).*(v_prev (i, j))-w*(W1 (i, j).*(v_prev (i+1, j))+W2 (i, j).*(v_now (i-1, j))+W3 (i, j).*(v_prev (i, j+1))+W4 (i, j).*(v_now (i, j-1)))/(W (i, j)); end end*__****** * [x y]=ndgrid(1:111,1:34); error=(sum(sum((abs(v_now-v_prev))/m*n))); v_prev=v_now; % Updating previous iteration matrix to the last iteration performed
surf(x,y,v_now) set(gca) title('potential ') xlabel('i') ylabel('j') zlabel('v_now') end
MATLAB: Where is the wrong in this equations between for loop
sor successive over relaxation method;
Best Answer