Laplace Equation using Gauss-Seidel Iteration | Numerical Methods Lab
Numerical Methods - Laplace Equation using Gauss-Seidel Iteration

Lab 7: Laplace Equation using Gauss-Seidel Iteration

Lab 7: Solution of Laplace Equation using Gauss-Seidel Iteration

Experiment Information

Experiment: Solution of Laplace Equation using Gauss-Seidel Iteration method

Course Code: Numerical Methods

Description: Complete lab report covering theory, algorithm, Python implementation and analysis of finite difference method for Laplace equation

Complete Lab Report PDF

1. Theory of Finite Difference Method for Laplace Equation

1.1 Mathematical formulation of Laplace equation

1.2 Finite difference approximation

1.3 Boundary conditions implementation

2. Gauss-Seidel Iteration Method

2.1 Iterative solution approach

2.2 Convergence criteria

2.3 Relaxation factor considerations

3. Implementation

3.1 Python code with numpy and matplotlib

3.2 Grid generation and initialization

3.3 Visualization of results

4. Observations

4.1 Convergence behavior

4.2 Effect of grid size

4.3 Computational efficiency

5. Results

5.1 Solution approximation

5.2 Error analysis

5.3 Graphical results

6. Discussion

6.1 Advantages and limitations

6.2 Comparison with other methods

6.3 Applications in engineering problems

Python Implementation of Gauss-Seidel Iteration for Laplace Equation

laplace_gauss_seidel.py
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def solve_laplace_gauss_seidel(grid_size=20, max_iter=1000, tolerance=1e-4, w=1.0): “”” Solve Laplace equation using Gauss-Seidel iteration with relaxation Parameters: grid_size : number of grid points along each axis max_iter : maximum number of iterations tolerance : convergence tolerance w : relaxation factor (1.0 for standard Gauss-Seidel) Returns: u : solution array iterations : number of iterations performed “”” # Initialize grid u = np.zeros((grid_size, grid_size)) # Set boundary conditions (example: u=1 on top boundary) u[0, :] = 1.0 # Top boundary # Other boundaries remain at 0 iterations = 0 error = 1.0 while error > tolerance and iterations < max_iter: error = 0.0 for i in range(1, grid_size-1): for j in range(1, grid_size-1): temp = u[i,j] u[i,j] = (1-w)*u[i,j] + w*0.25*(u[i+1,j] + u[i-1,j] + u[i,j+1] + u[i,j-1]) error += abs(u[i,j] - temp) error /= (grid_size-2)**2 # Average error per point iterations += 1 return u, iterations def plot_solution(u, title="Solution of Laplace Equation"): """Plot the solution in 3D surface plot""" x = np.linspace(0, 1, u.shape[0]) y = np.linspace(0, 1, u.shape[1]) X, Y = np.meshgrid(x, y) fig = plt.figure(figsize=(10, 7)) ax = fig.add_subplot(111, projection='3d') surf = ax.plot_surface(X, Y, u, cmap='viridis', rstride=1, cstride=1) ax.set_title(title, fontsize=14) ax.set_xlabel('X', fontsize=12) ax.set_ylabel('Y', fontsize=12) ax.set_zlabel('U', fontsize=12) fig.colorbar(surf, shrink=0.5, aspect=5) plt.show() # Solve and plot solution, iterations = solve_laplace_gauss_seidel(grid_size=20, max_iter=1000, tolerance=1e-5) print(f"Solution converged in {iterations} iterations") plot_solution(solution, "Solution of Laplace Equation using Gauss-Seidel Iteration")
×

Disclaimer

The educational materials provided on this website are intended as supplementary resources to support your learning journey. These lab reports are sample documents designed to help students understand proper formatting and content organization.

We have made every effort to ensure the accuracy of the content. However, we recommend students to perform their own experiments and prepare original reports. These samples should be used as references only.

We respect intellectual property rights. If you believe any content should be credited differently or removed, please don’t hesitate to contact us. We’re happy to make appropriate corrections or give proper attribution.

Leave a Comment

Scroll to Top