abs ( u - u_old )) num_iter += 1 u_square = np. copy ( u ) epsilon = 0.0 for j, y in enumerate ( y_vals ): for i, x in enumerate ( x_vals ): # for convenience, calculate all indices now kij = j * len ( x_vals ) + i kim1j = j * len ( x_vals ) + i - 1 kip1j = j * len ( x_vals ) + i + 1 kijm1 = ( j - 1 ) * len ( x_vals ) + i kijp1 = ( j + 1 ) * len ( x_vals ) + i if i = 0 : # this is the left boundary u = u_left elif i = len ( x_vals ) - 1 : # right boundary u = u_right elif j = 0 : # bottom boundary u = u_bottom elif j = len ( y_vals ) - 1 : # top boundary u = u_top else : # interior points u = ( u_old + u_old + u_old + u_old ) / 4.0 epsilon = np. ones ( num_pts ) u_left = 100 u_right = 100 u_bottom = 100 u_top = 0 # dummy value for residual variable epsilon = 1.0 num_iter = 0 while epsilon > 1e-2 : u_old = np. arange ( 0, length_y + 0.001, h ) num_pts = len ( x_vals ) * len ( y_vals ) # initial guess u = 100 * np. More than 100 million people use GitHub to discover, fork, and contribute to over 330 million projects. arange ( 0, length_x + 0.001, h ) y_vals = np. To associate your repository with the gauss-seidel topic, visit your repo's landing page and select 'manage topics.' Learn more. time () length_x = 1.0 length_y = 1.0 x_vals = np. 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\\end\), whereÄef heat_equation_jacobi ( h ): '''Solves heat equation using Jacobi iteration''' t0 = time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |