Gauss-Legendre Integration | Numerical Methods Lab
Numerical Methods - Gauss-Legendre Integration

Lab 5: Gauss-Legendre Numerical Integration

Lab 5: Gauss-Legendre Numerical Integration Method

Experiment Information

Experiment: Gauss-Legendre Numerical Integration

Course Code: Numerical Methods (SH202)

Description: Complete lab report covering theory, algorithm, Python implementation and analysis of Gauss-Legendre integration method

Complete Lab Report PDF

1. Theory of Gauss-Legendre Integration

1.1 Gaussian quadrature fundamentals

1.2 Legendre polynomials and roots

1.3 Weight factors calculation

2. Algorithm

2.1 Step-by-step procedure

2.2 Transformation of integration limits

2.3 Error estimation

3. Implementation

3.1 Python code with numpy

3.2 Function integration

3.3 Tabular data integration

4. Observations

4.1 Data recording table

4.2 Sample calculations

4.3 Accuracy comparison

5. Results

5.1 Integration results

5.2 Error analysis

5.3 Convergence behavior

6. Discussion

6.1 Advantages over other methods

6.2 Limitations and considerations

6.3 Applications in engineering

Python Implementation for Function Integration

gauss_legendre_function.py
import numpy as np from math import * def f(x): return e**(-x**2) def GL(f, a, b, n): xi, w = np.polynomial.legendre.leggauss(n) t = 0.5 * (xi + 1) * (b – a) + a I = np.sum(w * f(t) * (b – a) / 2) return I a = float(input(“Enter Lower limit:”)) b = float(input(“Enter Upper limit:”)) n = int(input(“Enter Number of quadrature points:”)) print(“Gauss-Legendre Integration: “, round(GL(f, a, b, n),7))

Python Implementation for Tabular Data Integration

gauss_legendre_tabular.py
import numpy as np from scipy.interpolate import interp1d def GL_tabular(x_data, y_data, n_points): # Create interpolation function f = interp1d(x_data, y_data, kind=’cubic’, fill_value=’extrapolate’) a = min(x_data) b = max(x_data) # Get Gauss-Legendre quadrature points and weights xi, w = np.polynomial.legendre.leggauss(n_points) # Transform points to [a,b] interval t = 0.5 * (xi + 1) * (b – a) + a # Evaluate function at quadrature points y = f(t) # Calculate integral I = np.sum(w * y * (b – a) / 2) return I # Example usage: x_data = [0, 0.5, 1.0, 1.5, 2.0] # Your x values y_data = [1, 0.8, 0.5, 0.3, 0.1] # Your y values n = 5 # Number of quadrature points result = GL_tabular(x_data, y_data, n) print(“Integral value:”, result)
×

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