function A=nma_laplaceRectNuemann(nx,ny,left,top,right,lambda,tol) %solves laplace PDE for rectangular region Nuemann BC %function A=nma_laplaceRectNuemann(nx,ny,left,top,right,lambda,tol) % % Function that solves the laplace PDE for rectangular region for % Nuemann boundary conditions at the bottom edge only. % %INPUT: % nx: number of grid points in the x-direction % ny: number of grid points in the y-direction % right: right edge boundary value % top: top edge boundary value % left: left edge boundary value % lambda: the value lambda to use for the relaxation method of Liebmann % tol: the absolute tolerance to check for convergance. % %OUTPUT: % the solution matrix. % %Author: Nasser Abbasi %May 25, 2003 TRUE = 1; FALSE = 0; A = zeros(nx+2,ny+2); A_old = A; % apply dirchlet conditions A(1,:) = top; A(:,1) = left; A(end,:) = 0; A(:,end) = right; %patch the 3 corners, just for cosmotics purposes A(1,1) = 0; A(end,1) = left; A(1,end) = 0; A(end,end) = right; A_old = A; converged = FALSE; nIter = 0; while(~converged) nIter = nIter+1; %fprintf('Iteration number %d\n',nIter); for(i=2+nx:-1:2) for(j=2:1:2+ny-1) if( i == 2+nx ) %insulated edge? A(i,j) = A(i,j+1) + A(i,j-1) + 2*A(i-1,j); else A(i,j) = A(i,j+1) + A(i,j-1) + A(i-1,j) + A(i+1,j); end A(i,j) = A(i,j)/4; A(i,j) = lambda*A(i,j) + (1-lambda)*A_old(i,j); end end [max_row , max_row_index] = max(A(2:end-1,2:end-1)); [max_element , max_col_index] = max(max_row); pos = [max_row_index(1)+1,max_col_index+1]; epsilonA = abs(A(pos(1),pos(2)) - A_old(pos(1),pos(2)))/A(pos(1),pos(2))*100; if( epsilonA < tol ) converged = TRUE; end A_old = A; %A %epsilonA end %A=A(2:end-1,2:end-1);