numeric-integration-lib
v1.0.0
Published
A library for the numerical evaluation of definite integrals
Downloads
150
Maintainers
Readme
Numeric Integration Lib
A simple Node.js library for numerical computation of definite integrals. Installation
npm install numeric-integration-lib
Usage javascript
import { midpointRule, trapezoidalRule, simpsonsRule } from 'numeric-integration-lib';
// Integrate f(x) = x^2 from 0 to 2. Exact answer: 8/3 (~2.6667) const fn = (x) => x * x;
console.log('Midpoint:', midpointRule(fn, 0, 2, 100)); console.log('Trapezoidal:', trapezoidalRule(fn, 0, 2, 100)); console.log('Simpson:', simpsonsRule(fn, 0, 2, 100));
Methods
All methods accept 4 arguments: (fn, a, b, n)
fn (Function): The function to integrate.
a (Number): Lower limit of integration.
b (Number): Upper limit of integration.
n (Number): Number of subdivisions (default: 1000).Available methods:
midpointRule: Midpoint rectangle method.
trapezoidalRule: Trapezoidal rule.
simpsonsRule: Simpson's 1/3 rule (n must be even, adjusted automatically).