Python code for gauss seidel method

broken image
broken image

To use the code, simply define the coefficient matrix and the right-hand side vector, and call the solve_poisson_equation function with the desired method and tolerance. The code also plots the solutions obtained from each method on the same graph for comparison. It provides separate functions for each iteration method, as well as a main function that solves the linear system using the selected method and returns the solution vector and the number of iterations required. The code uses the numpy library for matrix operations and the matplotlib library for plotting. The Over-Relaxation method is a modification of the Gauss-Seidel method that introduces a relaxation parameter to accelerate convergence.

broken image

The Gauss-Seidel method, on the other hand, updates the solution vector immediately after each element is computed, using the updated values of the neighboring elements. The Jacobi method performs one iteration at a time, updating the solution vector based on the current values of the neighboring elements. It also compares the number of iterations required for each method and plots the results. The function takes a coefficient matrix and a right-hand side vector as inputs and returns the solution vector of the linear system. This Python code provides a function that solves a two-dimensional Poisson equation using the Jacobi, Gauss-Seidel, and Over-Relaxation methods.

broken image