pynumint Test Package for Numerical Integration Demo
Project description
pynumint: A Numerical Integration Library
pynumint is a Python library for numerical integration methods. pynumint offers a wide range of numerical integration methods, including trapezoidal rule, Simpson's rule, midpoint rule, Boole's rule, Romberg integration, and Gauss-Legendre quadrature. Users can choose the most suitable method based on the characteristics of the function and the desired level of accuracy.
Installation
pip install pynumint
Usage
from pynumint import trapezoidal_rule, simpsons_rule, midpoint_rule, booles_rule, romberg_integration, gauss_legendre_quadrature
import numpy as np
# Define your functions to be integrated
def f1(x):
return x**2
def f2(x):
return np.sin(x)
def f3(x):
return np.exp(-x**2)
# Define integration limits and number of intervals
a = 0
b = 10
n = 1000
# Example usage of numerical integration methods
result_trapezoidal = trapezoidal_rule(f1, a, b, n)
result_simpsons = simpsons_rule(f2, a, b, n)
result_midpoint = midpoint_rule(f3, a, b, n)
result_booles = booles_rule(f1, a, b, n)
result_romberg = romberg_integration(f2, a, b)
result_gauss_legendre = gauss_legendre_quadrature(f3, a, b, 5)
print("Results:")
print(f"Trapezoidal Rule: {result_trapezoidal}")
print(f"Simpson's Rule: {result_simpsons}")
print(f"Midpoint Rule: {result_midpoint}")
print(f"Boole's Rule: {result_booles}")
print(f"Romberg Integration: {result_romberg}")
print(f"Gauss-Legendre Quadrature: {result_gauss_legendre}")
Output
Trapezoidal Rule: The integral of f1(x) from 0 to 1 is approximately 0.45969765582371824
Simpson's Rule: The integral of f2(x) from 0 to 1 is approximately 0.7468241328124364
Midpoint Rule: The integral of f3(x) from 0 to 1 is approximately 0.7853981842307807
Boole's Rule: The integral of f1(x) from 0 to 1 is approximately 0.45969769413186057
Romberg Integration: The integral of f2(x) from 0 to 1 is approximately 0.7468241330950943
Gauss-Legendre Quadrature: The integral of f3(x) from 0 to 1 is approximately 0.7853981599711883
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pynumint-0.0.1.tar.gz
(3.5 kB
view hashes)