This set of Python scripts provides tools for performing numerical integration using various methods including Gauss-Legendre and Gauss-Chebyshev quadrature, the trapezoidal rule, and Simpson's rule. The GaussQuad.py
file contains classes and functions for calculating basis polynomials and applying Gaussian Quadrature, while comparisons.py
includes methods for comparing the accuracy of different numerical integration techniques.
This file defines classes and methods for computing basis polynomials and performing Gauss Quadrature integration. It supports both Legendre and Chebyshev polynomials.
BasisPolynomials
: Class for calculating basis polynomials (Legendre, Chebyshev) and their derivatives.GaussQuadrature
: Class for performing Gauss Quadrature integration.Gaussian_Quad
: Function for executing Gaussian quadrature and returning the integral value, nodes, and weights.
- Import the
GaussQuadrature
class orGaussian_Quad
function. - Create a function to integrate.
- Use
Gaussian_Quad
to perform the integration, specifying the number of nodes, interval, and method ('legendre' or 'chebyshev').
When using GaussQuadrature.generate_and_save()
, the script generates a CSV file containing two columns:
- Nodes: The computed nodes for the quadrature.
- Weights: The corresponding weights for each node.
This file contains functions to compare the performance of various numerical integration methods.
trapezoidal_rule
: Implements the trapezoidal rule for integration.simpsons_rule
: Implements Simpson's rule for integration.compare_methods
: Compares the convergence and error of Gauss-Legendre, Gauss-Chebyshev, trapezoidal rule, and Simpson's rule.
- Import the required functions.
- Define the function to integrate and, if necessary, a modified version for use with Chebyshev quadrature.
- Call
compare_methods
with the standard and modified functions, the exact integral value for comparison, the interval of integration, and the maximum power of 2 for the number of intervals or nodes.
The compare_methods
function generates a plot showing the convergence and error of each method.
- Python 3.x
- Libraries:
numpy
,pandas
,matplotlib
,scipy
,math
Ensure that Python 3.x is installed and the required libraries are available. If not, they can be installed via pip:
pip install numpy pandas matplotlib scipy