Skip to main content

pynumint is a package for Numerical Integration tasks

Project description

pynumint: A Numerical Integration Library

ml drop (11)

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, Gauss-Legendre quadrature, Gauss-Chebyshev quadrature, Gauss-Laguerre quadrature, Gauss-Hermite quadrature, adaptive Simpson's rule, Monte Carlo integration, and double integrals. Users can choose the most suitable method based on the characteristics of the function and the desired level of accuracy.

Link to PyPi

Installation

pip install pynumint

Usage

from pynumint import trapezoidal_rule, simpsons_rule, midpoint_rule, booles_rule, romberg_integration, gauss_legendre_quadrature, gauss_chebyshev_quadrature, gauss_laguerre_quadrature, gauss_hermite_quadrature, adaptive_simpsons_rule, monte_carlo_integration, double_integral, simpsons_rule_with_error
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)

def f4(x, y):
    return x * y

# Define integration limits and number of intervals
a = 0
b = 10
n = 1000

Trapezoidal Rule

result_trapezoidal = trapezoidal_rule(f1, a, b, n)

Simpson's Rule

result_simpsons = simpsons_rule(f2, a, b, n)

Midpoint Rule

result_midpoint = midpoint_rule(f3, a, b, n)

Boole's Rule

result_booles = booles_rule(f1, a, b, n)

Romberg Integration

result_romberg = romberg_integration(f2, a, b)

Gauss-Legendre Quadrature

result_gauss_legendre = gauss_legendre_quadrature(f3, a, b, 5)

Gauss-Chebyshev Quadrature

result_gauss_chebyshev = gauss_chebyshev_quadrature(f3, 5)

Gauss-Laguerre Quadrature

result_gauss_laguerre = gauss_laguerre_quadrature(f3, 5)

Gauss-Hermite Quadrature

result_gauss_hermite = gauss_hermite_quadrature(f3, 5)

Adaptive Simpson's Rule

result_adaptive_simpsons = adaptive_simpsons_rule(f3, a, b, 1e-6)

Monte Carlo Integration

result_monte_carlo = monte_carlo_integration(f3, a, b)

Double Integrals

result_double_integral = double_integral(f4, 0, 1, 0, 1)

Simpson's rule with error

result_simpsons_error, error_estimate = simpsons_rule_with_error(f2, a, b, n)

Print results

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}")
print(f"Gauss-Chebyshev Quadrature: {result_gauss_chebyshev}")
print(f"Gauss-Laguerre Quadrature: {result_gauss_laguerre}")
print(f"Gauss-Hermite Quadrature: {result_gauss_hermite}")
print(f"Adaptive Simpson's Rule: {result_adaptive_simpsons}")
print(f"Monte Carlo Integration: {result_monte_carlo}")
print(f"Double Integral: {result_double_integral}")
print(f"Double Integral: {result_double_integral}")
print(f"Simpson's Rule with Error Estimation: {result_simpsons_error} with an error estimate of {error_estimate}")

Output

Results:
Trapezoidal Rule: 333.33350000000013
Simpson's Rule: 1.8390715291786217
Midpoint Rule: 0.8862269254527569
Boole's Rule: 333.3333333333334
Romberg Integration: 1.839071529076259
Gauss-Legendre Quadrature: 0.9622861833849173
Gauss-Chebyshev Quadrature: 2.026469405000093
Gauss-Laguerre Quadrature: 0.5408201719540809
Gauss-Hermite Quadrature: 1.260069748687603
Adaptive Simpson's Rule: 0.443113467730597
Monte Carlo Integration: 0.7746479690195586
Double Integral: 0.25507601265177027
Simpson's Rule with Error Estimation: 1.8390715291786217 with an error estimate of 5.555553794065748e-06

Project details


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.2.3.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pynumint-0.2.3-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file pynumint-0.2.3.tar.gz.

File metadata

  • Download URL: pynumint-0.2.3.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.4

File hashes

Hashes for pynumint-0.2.3.tar.gz
Algorithm Hash digest
SHA256 36feda0160f5953b73825d3bb7c46a59e66713b2aa8b101774cef98471ed2018
MD5 e0479f08d65d6c153e131f3b85f78526
BLAKE2b-256 c58d6fec3a8e3334611e8f5144e1319dd66a75adeb35664a77ffb13a9b88c87f

See more details on using hashes here.

File details

Details for the file pynumint-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: pynumint-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.4

File hashes

Hashes for pynumint-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 886da919bc8ffc5bd8e1c0be1f0ece8355f2da4f529a32d71f6feedd69dd5b24
MD5 3cacef496518d2343b6ace05ef95e1f1
BLAKE2b-256 a80fe12c554f642d8f06b51b1975dc143bd4eda08b6fe7e937aa54e75a698232

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page