Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pynumint

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pynumint

pynumint is a package for Numerical Integration tasks

  • 0.2.3
  • Source
  • PyPI
  • Socket score

Maintainers
2

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

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc