Skip to main content

Calculate area under curve

Project description

  • Version 1.0.6
  • Python 3.7+ module to calculate riemann sum area under a curve
  • Copyright 2019 Steven Mycynek
  • Supports
    • simpson, trapezoid, and midpoint algorithms,
    • n-degree single variable polynomials, including fractional exponents,
    • variable step size

USAGE = """ -p|--poly {DegreeN1:CoefficientM1, DegreeN2:CoefficientM2, ...}... -l|--lower <lower_bound> -u|--upper <upper_bound> -s|--step <step> -a|--algorithm <simpson | trapezoid | midpoint>

  • This was just a fun experiment I did on a couple airplane rides and might not be suitable for production use.
  • Try a simple function you can integrate by hand easily, like f(x) = x^3 from [0-10], and compare that to how accurate the midpoint, trapezoid, and simpson approximations are with various steps sizes.

  • Why not use numpy? You probably should, but I wanted to do everything from scratch for fun.


python3 --polynomial {3:1} --lower 0 --upper 10 --step .1 --algorithm simpson


import area_under_curve as auc

algorithm = auc.get_algorithm("simpson")

bounds = auc.Bounds(0, 10, .1)

polynomial = auc.Polynomial({3:1})

params = auc.Parameters(polynomial, bounds, algorithm)

AREA = auc.area_under_curve(params.polynomial, params.bounds, params.algorithm)


Also try out and

Use poetry install and poetry shell for a python3 environment with dev dependencies.

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

area_under_curve-1.0.6.tar.gz (7.7 kB view hashes)

Uploaded source

Built Distribution

area_under_curve-1.0.6-py2.py3-none-any.whl (6.6 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page