Print ( 'Residual: %.7f ' % resid_ave ) # Count iterations count = count + 1 print ( ' \n ' ) print ( 'SOR conducted a total of %g iterations to obtain approximate solution.' % count ) print ( 'Final residual: %. # Residual residual = a * psi + b * psi + c * psi + d * psi + e * psi - f # Update psi value psi += - w * residual / e # Update resid_ave as a sum of residuals resid_ave += abs ( residual ) cnt_points += 1 # Get average residual resid_ave = resid_ave / cnt_points # Print every 1000-dth residual if count % 1000=0: # Set count for points in checker-boarding cnt_points = 0 # Loop over internal points only for i in range ( 1, n - 1 ): for j in range ( 1, n - 1 ): # Checker-boarding if (( i + j ) % 2)=count%2: Using the two distinct finite difference methods, Gauss-Seidel and Jacobi, numerical solutions for potential and electric field are computed, which can be compared with an analytical solution. count = 0 while resid_ave > resid_crit : # Set at 0 so we can sum it up later resid_ave = 0. w = 1.7 resid_crit = 1.0e-6 # Arbitrary value at the begining, higher than resid_crit resid_ave = 100.